~kris/dots

srice

ref: e9b48d06a8541f3eda5c4db90382ab3c77183afb srice/.local/bin/dmenu/dcreate -rwxr-xr-x 3.9 KiB
e9b48d06 — Kris Yotam xprofile: systemd-aware pipewire start + blueman-applet; sb-internet: tolerate missing /proc/net/wireless 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
set -euo pipefail

###############################################################################
# DCREATE — dmenu content creator for krisyotam.com
#
# Maintainer:   Kris Yotam <krisyotam@pm.me>
# License:      MIT
# Created:      2026-02-15
# Updated:      2026-02-26
# Description:  Create new content entries via dmenu. Collects title + preview,
#               auto-generates slug, validates uniqueness against ~/content/,
#               then spawns Claude in st terminal to determine metadata and
#               write a YAML-frontmatter .mdx file.
###############################################################################

CONTENT_DIR="$HOME/content"

declare -A TYPE_ICONS=(
    [papers]="󰈙" [blog]="󰬞" [essays]="󰬝" [notes]="󰏪"
    [diary]="󰃮" [progymnasmata]="󰑴" [reviews]="󰓥"
    [fiction]="󰗊" [verse]="󰊈" [news]="󰎕" [ocs]="󰚥"
)

ALL_TYPES=(blog diary essays fiction news notes ocs papers progymnasmata reviews verse)

notify() { notify-send "dcreate" "$1" 2>/dev/null || true; }

slugify() {
    echo "$1" |
        tr '[:upper:]' '[:lower:]' |
        sed 's/[^a-z0-9 -]//g' |
        sed 's/  */ /g; s/ /-/g; s/--*/-/g; s/^-//; s/-$//'
}

# Check if slug.mdx already exists in any content subdirectory
check_slug_globally() {
    local slug="$1"
    for dir in "$CONTENT_DIR"/*/; do
        [ -d "$dir" ] || continue
        if [ -f "$dir/${slug}.mdx" ]; then
            echo "$(basename "$dir"):${slug}.mdx"
            return
        fi
    done
}

# Select type
type_menu() {
    local entries=""
    for t in "${ALL_TYPES[@]}"; do
        entries+="${TYPE_ICONS[$t]:-󰈙}  $t"$'\n'
    done
    echo "$entries" | dmenu -i -l 12 -p "create:" | awk '{print $2}'
}

# Main
type="$(type_menu)"
[[ -z "$type" ]] && exit 0

# Get title
title="$(echo "" | dmenu -p "title:")"
[[ -z "$title" ]] && exit 0

# Generate and validate slug
slug="$(slugify "$title")"
collision="$(check_slug_globally "$slug")"
if [[ -n "$collision" ]]; then
    notify "Slug collision: $slug ($collision)"
    slug="$(echo "$slug" | dmenu -p "collision! alt slug:")"
    [[ -z "$slug" ]] && exit 0
    slug="$(slugify "$slug")"
    collision="$(check_slug_globally "$slug")"
    if [[ -n "$collision" ]]; then
        notify "Still colliding: $slug. Aborting."
        exit 1
    fi
fi

# Get preview
preview="$(echo "" | dmenu -p "preview:")"

# Type-specific extra fields
extra_prompt=""
if [[ "$type" == "verse" ]]; then
    verse_type="$(printf 'haiku\nsonnet\nfree-verse\node\nlimerick\nvillanelle\nother' | dmenu -i -l 7 -p "verse type:")"
    [[ -n "$verse_type" ]] && extra_prompt="verse_type: $verse_type"
fi

# Ensure target directory exists
target_dir="$CONTENT_DIR/$type"
mkdir -p "$target_dir"

date="$(date +%Y-%m-%d)"
target_file="$target_dir/${slug}.mdx"

# Build Claude instruction
instruction="You are creating a new $type entry as a YAML-frontmatter .mdx file.

=== USER INPUT ===
Type: $type
Title: $title
Preview: ${preview:-"(none)"}
Slug: $slug
Date: $date
${extra_prompt:+Extra: $extra_prompt}

=== TARGET FILE ===
$target_file

=== YAML FORMAT ===
The file MUST use this exact YAML frontmatter structure:

---
title: $title
slug: $slug
type: $type
category: <choose-appropriate-category>
start_date: '$date'
end_date: ''
state: active
preview: ${preview:-"<write-a-one-line-preview>"}
status: Draft
confidence: <certain|likely|possible|unlikely>
importance: <1-10>
tags:
  - <tag1>
  - <tag2>
  - <tag3>
---

Content goes here...

=== YOUR TASK ===

1. ANALYZE the title and preview to determine: category, tags, confidence, importance.
2. WRITE the .mdx file to: $target_file
3. Use the Write tool to create the file with proper YAML frontmatter.
4. VERIFY the file was created.

Execute this now without asking for confirmation."

# Spawn Claude in st terminal
notify "Creating: $title ($slug)"
st -e bash -c "claude -p '$(echo "$instruction" | sed "s/'/'\\\\''/g")'; echo; echo 'Press Enter to close...'; read" &
disown