Files
git.taskfile.build/bin/list-prompts
T

48 lines
1.3 KiB
Plaintext
Executable File

list-prompts() {
local prompts_dir="prompts"
if [[ ! -d "$prompts_dir" ]]; then
echo "No prompts directory found."
return 0
fi
local files=("$prompts_dir"/[0-9][0-9]_*.md)
if [[ ${#files[@]} -eq 0 ]]; then
echo "No prompt files found."
return 0
fi
local max_id_len=2
local max_title_len=10
for file in "${files[@]}"; do
local id=${file#"$prompts_dir"/}
id=${id%%_*}
local title=$(grep -m1 '^title:' "$file" | sed 's/^title:[[:space:]]*//; s/^"\(.*\)"$/\1/')
if [[ ${#id} -gt max_id_len ]]; then
max_id_len=${#id}
fi
if [[ ${#title} -gt max_title_len ]]; then
max_title_len=${#title}
fi
done
printf "| %-${max_id_len}s | %-${max_title_len}s |
" "id" "title"
printf "|-%s-|-%s-|
" "$(printf '%*s' "$max_id_len" '' | tr ' ' '-')" "$(printf '%*s' "$max_title_len" '' | tr ' ' '-')"
for file in "${files[@]}"; do
local id=${file#"$prompts_dir"/}
id=${id%%_*}
local title=$(grep -m1 '^title:' "$file" | sed 's/^title:[[:space:]]*//; s/^"\(.*\)"$/\1/')
printf "| %-${max_id_len}s | %-${max_title_len}s |
" "$id" "$title"
done
}