Skip to content

Commit d70d26b

Browse files
committed
[scripts] ,auto-commit: allow regeneration, consolidate editing
1 parent 7e4e46f commit d70d26b

1 file changed

Lines changed: 50 additions & 22 deletions

File tree

scripts/.local/bin/random/,auto-commit

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,67 @@ get_changes() {
1515
fi
1616
}
1717

18-
changes=$(get_changes "$1")
18+
commit="${1:-@}"
19+
changes=$(get_changes "$commit")
1920
[ -n "$1" ] && shift
2021

2122
if [ -z "$changes" ]; then
2223
echo "No changes to commit"
2324
exit 1
2425
fi
2526

26-
printf "Generating message...\r"
27-
echo "$changes" | esa +commit "$*" >/tmp/auto-pr-message
28-
printf "\033[2K" # clear line
27+
echo "$changes" | esa -- +commit "$*" | tee /tmp/auto-pr-message
2928

30-
cat /tmp/auto-pr-message
31-
read -n 1 -p "Edit commit message? (y/N): " edit_confirm
29+
while true; do
30+
read -n 1 -p "Use commit message (Y/n/r/e/m/?): " confirm
31+
commit_msg="$(cat /tmp/auto-pr-message)"
3232

33-
if [ "$edit_confirm" = "y" ]; then
34-
vim /tmp/auto-pr-message
35-
fi
33+
case $confirm in
34+
[nN])
35+
exit 0
36+
;;
37+
[eE])
38+
vim /tmp/auto-pr-message
39+
break
40+
;;
41+
[rR])
42+
printf "\033[2K\r" # clear line
43+
echo
44+
echo "$changes" | esa -- +commit "$message" | tee /tmp/auto-pr-message
45+
continue
46+
;;
47+
[yY] | "")
48+
break
49+
;;
50+
[mM])
51+
printf "\033[2K\r" # clear line
52+
read -rp "Enter message for esa: " message
53+
esa -c -- +commit "$message" | tee /tmp/auto-pr-message
54+
continue
55+
;;
56+
[\?])
57+
echo "Options:
58+
y/Y: Use commit message
59+
n/N: Skip commit
60+
r/R: Re-run esa with the same changes
61+
e/E: Edit commit message
62+
m/M: Enter a new message for esa
63+
?: Show this help"
64+
continue
65+
;;
66+
*)
67+
echo "Invalid input. Please enter 'y' or 'n'."
68+
exit 1
69+
;;
70+
esac
71+
done
3672

37-
read -n 1 -p "Use commit message (Y/n): " confirm
3873
commit_msg="$(cat /tmp/auto-pr-message)"
39-
40-
echo
41-
if [ "$confirm" != "n" ]; then
42-
if [ -d "$base/.jj" ]; then
43-
jj desc -m "$commit_msg" -r "${1-@}"
44-
elif [ -d "$base/.git" ]; then
45-
git commit -m "$commit_msg"
46-
else
47-
echo "No git or jj repository found"
48-
exit 1
49-
fi
74+
if [ -d "$base/.jj" ]; then
75+
jj desc -m "$commit_msg" -r "$commit"
76+
elif [ -d "$base/.git" ]; then
77+
git commit -m "$commit_msg"
5078
else
51-
echo "Commit aborted"
79+
echo "No git or jj repository found"
5280
exit 1
5381
fi

0 commit comments

Comments
 (0)