git: Add git-abort & git-continue

I find typing `git {rebase,merge,...} --{continue,abort}` a bit
annoying, since it is a lot of typing. I have added an alias for `rebase
--continue` (grc), but the problem remained for the other commands.

Add a script that continues or aborts the ongoing process by detecting
it automatically.
This commit is contained in:
2025-06-19 13:15:41 +02:00
parent 9ed2f526da
commit 740c0b2fd7
3 changed files with 34 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
# the right directory, as shell commands in git aliases are executed
# from the top-level directory of the repository.
abort = "!git-zsh-autoload abort"
autosquash = -c sequence.editor=/bin/true rebase -i --autosquash
autofixup= autosquash
c = commit
@@ -17,6 +18,7 @@
cow = checkout-worktree
co = checkout
commit-last-msg = "!git-zsh-autoload commit-last-msg"
continue = "!git-zsh-autoload continue"
clm = commit-last-msg
last-msg = commit-last-msg
recommit = commit-last-msg --no-edit

View File

@@ -0,0 +1,31 @@
#!/usr/bin/env zsh
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Julian Prein
#
# Abort or continue the current rebase/merge/cherry-pick/revert/am (execute as
# git-abort or git-continue).
emulate -L zsh -o err_return -o no_unset
local gitdir
gitdir="$(git rev-parse --git-dir)" || return
local flag="${${0:t}#git-}"
local cmd
if [[ -e $gitdir/REBASE_HEAD ]]; then
cmd=rebase
elif [[ -e $gitdir/MERGE_HEAD ]]; then
cmd=merge
elif [[ -e $gitdir/CHERRY_PICK_HEAD ]]; then
cmd=cherry-pick
elif [[ -e $gitdir/REVERT_HEAD ]]; then
cmd=revert
elif [[ -e $gitdir/rebase-apply/applying ]]; then
cmd=am
else
printf "Nothing to %s at the moment\n" "$flag"
return 1
fi
git "$cmd" "--$flag"

View File

@@ -0,0 +1 @@
git-abort