dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit 59cede289a62a7243b7538345f4a674c9edafe39
parent d0aa98e54ea704e8234b3ab30275f030bb65254e
Author: hhvn <dev@haydenvh.com>
Date:   Sun,  7 Mar 2021 03:25:57 +0000

.config/git/add-commit: support for COMMIT_EDITMSG

Diffstat:
M.config/git/add-commit | 53++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/.config/git/add-commit b/.config/git/add-commit @@ -4,20 +4,51 @@ # output: git add LICENSE project.c; git commit -m "LICENSE project.c: new email addr" die(){ - echo "error: no filenames extracted from (non-existant)* commit message" + echo "error: no filenames extracted from commit message" exit 1 } -# [][][^][]*[][] is one of the ugliest regexes I've ever constructed -# It is meant to get rid of the [NEW] from "thing.1[NEW]: add manpage" +for n in $(seq $#) +do + [ "$(eval "echo \$$n")" = "-m" ] && inline=y && break +done -echo "$@" | grep ".*-m *[^:]*:" >/dev/null || die -files=$(echo "$@" | sed 's/[][][^][]*[][]//g' | sed -E 's/.*-m *([^:]*):.*/\1/') +[ "$inline" = "y" ] && { + echo "$@" | grep ".*-m *[^:]*:" >/dev/null || die + + # [][][^][]*[][] is one of the ugliest regexes I've ever constructed + # It is meant to get rid of the [NEW] from "thing.1[NEW]: add manpage" + files=$(echo "$@" | sed 's/[][][^][]*[][]//g' | sed -E 's/.*-m *([^:]*):.*/\1/') + + git add $files + + while [ $# != 0 ] + do + printf '%s\0' "$1" + shift + done | xargs -0 git commit +} + +[ "$inline" != "y" ] && { + # in non-inline mode, take list of files to add + # then format these into the COMMIT_EDITMSG file + + list="$@" + while [ $# -ne 0 ] + do + printf "%s\0" "$1" + shift + done | xargs -0 git add || exit 1 + + echo "$list:" > .git/COMMIT_EDITMSG + sum=$(sha256sum .git/COMMIT_EDITMSG) + ${EDITOR:-vim} .git/COMMIT_EDITMSG + sum2=$(sha256sum .git/COMMIT_EDITMSG) + + [ "$sum" != "$sum2" ] && git commit -F .git/COMMIT_EDITMSG || { + echo "error: COMMIT_EDITMSG not changed" + exit 1 + } +} -git add $files -while [ $# != 0 ] -do - printf '%s\0' "$1" - shift -done | xargs -0 git commit