From 740c0b2fd7c16194714cb2e14642b2086e0b4ba7 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 19 Jun 2025 13:15:41 +0200 Subject: [PATCH] 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. --- .config/git/config | 2 ++ .config/zsh/autoload/git/git-abort | 31 +++++++++++++++++++++++++++ .config/zsh/autoload/git/git-continue | 1 + 3 files changed, 34 insertions(+) create mode 100755 .config/zsh/autoload/git/git-abort create mode 120000 .config/zsh/autoload/git/git-continue diff --git a/.config/git/config b/.config/git/config index 982f9c6..0aaea4e 100644 --- a/.config/git/config +++ b/.config/git/config @@ -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 diff --git a/.config/zsh/autoload/git/git-abort b/.config/zsh/autoload/git/git-abort new file mode 100755 index 0000000..ec8edce --- /dev/null +++ b/.config/zsh/autoload/git/git-abort @@ -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" diff --git a/.config/zsh/autoload/git/git-continue b/.config/zsh/autoload/git/git-continue new file mode 120000 index 0000000..31ceda5 --- /dev/null +++ b/.config/zsh/autoload/git/git-continue @@ -0,0 +1 @@ +git-abort \ No newline at end of file