57 lines
1.7 KiB
Bash
Executable File
57 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
list-prompts() {
|
|
local prompts_dir="prompts"
|
|
if [ -n "$1" ]; then
|
|
prompts_dir="$1/prompts"
|
|
fi
|
|
|
|
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
|
|
local max_state_len=5
|
|
|
|
for file in "${files[@]}"; do
|
|
local id=${file#"$prompts_dir"/}
|
|
id=${id%%_*}
|
|
|
|
local title=$(grep -m1 '^title:' "$file" | sed 's/^title:[[:space:]]*//; s/^"\(.*\)"$/\1/')
|
|
local state=$(grep -m1 '^state:' "$file" | sed 's/^state:[[: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
|
|
|
|
if [[ ${#state} -gt max_state_len ]]; then
|
|
max_state_len=${#state}
|
|
fi
|
|
done
|
|
|
|
printf "| %-${max_id_len}s | %-${max_title_len}s | %-${max_state_len}s |\n" "id" "title" "state"
|
|
printf "|-%s-|-%s-|-%s-|\n" "$(printf '%*s' "$max_id_len" '' | tr ' ' '-')" "$(printf '%*s' "$max_title_len" '' | tr ' ' '-')" "$(printf '%*s' "$max_state_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/')
|
|
local state=$(grep -m1 '^state:' "$file" | sed 's/^state:[[:space:]]*//; s/^"\(.*\)"$/\1/')
|
|
|
|
printf "| %-${max_id_len}s | %-${max_title_len}s | %-${max_state_len}s |\n" "$id" "$title" "$state"
|
|
done
|
|
} |