Skip to content

Commit f27f8ef

Browse files
authored
chore(release): bump version to 0.1.1 (#13)
- Adds enhanced fzf picker (new format, shows full commit message in preview window) - Update demo to reflect changes
1 parent 5c4558b commit f27f8ef

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

release/cfme

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ root_command() {
5959

6060
# Parse AI response and let user select a commit message
6161
mapfile -t headers < <(extract_headers_from_response "$response")
62-
selected_header="$(pick_from_headers headers)"
62+
selected_header="$(pick_from_headers headers "$response")"
6363
selected_entry="$(select_entry "$selected_header" "$response")"
6464

6565
# Build the commit message and open it in the user's editor for review/editing
@@ -582,9 +582,9 @@ load_vars_map() {
582582
# Add defaults to the map
583583
referenced_map["<__GIT_DIFF__>"]="$(git diff --cached)"
584584

585-
referenced_map["<__RESPONSE_REQUIREMENTS__>"]="$(
585+
referenced_map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="$(
586586
cat <<'EOF'
587-
**Requirements:**
587+
**Response Format Requirements:**
588588
589589
- Each commit message MUST include a 'header'.
590590
- Optionally include 'body' and 'footer', ONLY if a 'header'
@@ -594,7 +594,7 @@ load_vars_map() {
594594
595595
```yaml
596596
commitMessages:
597-
- header: "<type>[optional scope]: <description>"
597+
- header: "<required header>"
598598
body: "<optional body>"
599599
footer: "<optional footer>"
600600
score: <integer 0-100 representing confidence that this is the best commit message>
@@ -623,19 +623,47 @@ EOF
623623
# src/lib/pick_from_headers.sh
624624
pick_from_headers() {
625625
local -n headers_ref=$1
626+
local response="$2"
626627

627628
# Quit if no headers are provided
628629
if [[ ${#headers_ref[@]} -eq 0 ]]; then
629630
echo "No headers available to pick from. Maybe the AI response is empty or incorrectly formatted? You can test this by running the command again with the -r flag." >&2
630631
return 1
631632
fi
632633

633-
selected_line=$(printf '%s\n' "${headers_ref[@]}" | sort -rn | fzf --ansi --prompt="Select commit message: " --preview "echo {}")
634+
# Prerender all full messages to a temp file
635+
local temp_file=$(mktemp)
636+
local count=1 # Start at 1 to match nl numbering
637+
while IFS= read -r header; do
638+
local header_only="${header#* }" # Remove score prefix
639+
echo "=== MESSAGE $count ===" >>"$temp_file"
640+
echo "$response" | yq eval ".commitMessages[] | select(.header==\"$header_only\") | .header" - >>"$temp_file"
641+
local body=$(echo "$response" | yq eval ".commitMessages[] | select(.header==\"$header_only\") | .body // \"\"" -)
642+
local footer=$(echo "$response" | yq eval ".commitMessages[] | select(.header==\"$header_only\") | .footer // \"\"" -)
643+
[[ -n "$body" && "$body" != "null" ]] && echo "" >>"$temp_file" && echo "$body" >>"$temp_file"
644+
[[ -n "$footer" && "$footer" != "null" ]] && echo "" >>"$temp_file" && echo "$footer" >>"$temp_file"
645+
echo "" >>"$temp_file"
646+
((count++))
647+
done < <(printf '%s\n' "${headers_ref[@]}" | sort -rn)
648+
649+
# Add a final marker to ensure the last message is captured correctly
650+
echo "=== END ===" >>"$temp_file"
651+
652+
selected_line=$(printf '%s\n' "${headers_ref[@]}" | sort -rn | sed 's/^[0-9]* //' | nl -w1 -s' | ' | fzf --ansi \
653+
--prompt="Select commit message: " \
654+
--preview "num=\$(echo {} | grep -o '^[0-9]*'); sed -n \"/=== MESSAGE \$num ===/,/=== MESSAGE/p\" '$temp_file' | head -n -1 | tail -n +2" \
655+
--preview-window=wrap)
656+
657+
local exit_code=$?
658+
rm -f "$temp_file"
659+
634660
[[ -z "$selected_line" ]] && {
635661
echo "No selection, aborting." >&2
636662
return 1
637663
}
638-
echo "${selected_line#* }"
664+
665+
# Remove the rank number and separator
666+
echo "${selected_line}" | sed 's/^[0-9]* | //'
639667
}
640668

641669
# src/lib/print_if_not_silent.sh
@@ -695,7 +723,7 @@ function validate_vars_map() {
695723
continue
696724
fi
697725
if ! grep -q "$key" <<<"$prompt"; then
698-
if [[ "$key" == "<__RESPONSE_REQUIREMENTS__>" || "$key" == "<__GIT_DIFF__>" ]]; then
726+
if [[ "$key" == "<__RESPONSE_FORMAT_REQUIREMENTS__>" || "$key" == "<__GIT_DIFF__>" ]]; then
699727
# This key is mandatory
700728
echo "Error: key '$key' is essential for cfme to function, but not present in the prompt." >&2
701729
return 1
@@ -901,7 +929,7 @@ before_hook() {
901929

902930
# :command.initialize
903931
initialize() {
904-
declare -g version="0.1.0"
932+
declare -g version="0.1.1"
905933
set -e
906934

907935
# :command.environment_variables_default

src/bashly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: cfme
22
help: Commit For Me - Generate commit messages for staged files using aichat
3-
version: 0.1.0
3+
version: 0.1.1
44

55
environment_variables:
66
- name: CFME_CONFIG_DIR

0 commit comments

Comments
 (0)