Commit changes after creating or editing files

This commit is contained in:
Oliver Davies 2025-09-06 22:17:04 +01:00
parent f28d640795
commit 34e129306e
2 changed files with 28 additions and 0 deletions

View file

@ -10,6 +10,7 @@
bashInteractive
coreutils
fzf
git
];
text = builtins.readFile ./script.sh;

View file

@ -3,6 +3,28 @@ ZET_DIR="$HOME/Documents/zet"
mkdir -p "$ZET_DIR"
commit_changes() {
filename="$1"
commit_message="$2"
git -C "$ZET_DIR" diff --quiet "$filename" || {
read -rp "Commit?: " commit_choice
if [[ "$commit_choice" =~ ^[Yy]$ ]]; then
git -C "$ZET_DIR" add "$filename"
commit_message="${commit_message//$ZET_DIR\//}"
commit_message="${commit_message//\/index.adoc/}"
git -C "$ZET_DIR" commit -m "$commit_message"
echo "Changes committed."
else
echo "Changes not committed."
fi
}
}
delete_zet() {
id="$1"
dir="${ZET_DIR}/${id}"
@ -22,6 +44,8 @@ edit_zet() {
if [[ -f "$file" ]]; then
"$EDITOR" "$file"
commit_changes "$file" "Edited $file"
else
result="$(search_zets "$query")"
result_count="$(echo "$result" | grep -c '^')"
@ -76,6 +100,9 @@ new_zet() {
echo "= $title" > "$filename"
"$EDITOR" "$filename"
run_git_command add --intent-to-add "$filename"
commit_changes "$filename" "Added $filename"
}
search_zets() {