Files
git.taskfile.build/bin/create-prompt
T
Janik von Rotz 6f93c35033 feat: update create-prompt to accept title as argument and add new prompt file
- Modified create-prompt to accept title as command-line argument instead of interactive input
- Added usage message when title is missing
- Fixed numeric comparison in prompt numbering logic to handle leading zeros correctly
- Added new prompt file 09_add-cluster-and-partner-list-view-to-website-kubectl.md
- Changed task.template permissions from executable to readable (755 → 644)
2026-02-17 13:55:38 +01:00

50 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
create-prompt() {
local title="$1"
if [[ -z "$title" ]]; then
echo "Error: Title cannot be empty."
echo "Usage: task create-prompt <title>"
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 [[ -n "$num" ]] && (( 10#$num > highest_num )); then
highest_num=$((10#$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
export PROMPT_TITLE="$title"
export PROMPT_ID="$padded_num"
envsubst < "$HOME/taskfile.build/prompt.md.template" > "$filepath"
if [[ -n "$EDITOR" ]]; then
"$EDITOR" "$filepath"
else
echo "File created: $filepath"
fi
}