Files
git.taskfile.build/bin/create-prompt
T
Janik von Rotz 8f786f1822 feat: add create-prompt and list-prompt commands for managing prompt files
- Added `create-prompt` command to create new prompt files from template with sequential numbering
- Added `list-prompt` command to display all prompt files in a formatted table
- Added `prompt.md.template` file as base template for new prompts
- Added `prompts/08_add-prompt-commands.md` prompt file documenting the addition of prompt management commands
- Added `create-prompt` and `list-prompt` commands to help table in `task.template`
- Added `create-prompt` and `list-prompt` documentation to `library.md`
- Updated `task.template` to include `create-prompt`, `list-prompt`, and `setup-completion` commands in help table
- Updated `library.md` to include `create-prompt` and `list-prompt` commands in LLM section
2026-02-16 09:05:15 +01:00

61 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
create-prompt() {
local title
echo "Enter the title of the prompt:"
read -r title
if [[ -z "$title" ]]; then
echo "Error: Title cannot be empty."
return 1
fi
local prompts_dir="prompts"
if [[ ! -d "$prompts_dir" ]]; then
mkdir -p "$prompts_dir"
fi
local highest_num=0
for file in "$prompts_dir"/[0-9][0-9]_*.md; do
if [[ -f "$file" ]]; then
local num=${file#"$prompts_dir"/}
num=${num%%_*}
num=${num//[!0-9]/}
if (( num > highest_num )); then
highest_num=num
fi
fi
done
local next_num=$((highest_num + 1))
local padded_num=$(printf "%02d" "$next_num")
local slug=$(echo "$title" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd '[:alnum:]-')
local filename="${padded_num}_${slug}.md"
local filepath="$prompts_dir/$filename"
if [[ -f "$filepath" ]]; then
echo "Error: File $filepath already exists."
return 1
fi
cp "prompt.md.template" "$filepath"
local temp_file="${filepath}.tmp"
awk -v title="$title" '
BEGIN { done = 0 }
{
if (!done && $0 ~ /^title:/) {
print "title: " title
done = 1
} else {
print $0
}
}' "$filepath" > "$temp_file"
mv "$temp_file" "$filepath"
if [[ -n "$EDITOR" ]]; then
"$EDITOR" "$filepath"
else
echo "File created: $filepath"
fi
}