diff --git a/.config/git/config b/.config/git/config index 4de1397..81deea4 100644 --- a/.config/git/config +++ b/.config/git/config @@ -4,14 +4,19 @@ addIgnoredFile = off detachedHead = off [alias] + # NOTE: git-zsh-autoload (./zsh-autoload.sh) is a small wrapper that + # launches autoloadable zsh functions (.config/zsh/autoload/git/*) in + # the right directory, as shell commands in git aliases are executed + # from the top-level directory of the repository. + autosquash = -c sequence.editor=/bin/true rebase -i --autosquash autofixup= autosquash c = commit changes = flog HEAD...FETCH_HEAD - checkout-worktree = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-checkout-worktree\"" + checkout-worktree = "!git-zsh-autoload checkout-worktree" cow = checkout-worktree co = checkout - commit-last-msg = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-commit-last-msg\"" + commit-last-msg = "!git-zsh-autoload commit-last-msg" clm = commit-last-msg last-msg = commit-last-msg recommit = commit-last-msg --no-edit @@ -20,20 +25,20 @@ ft = fetch-tags-only filter-repo = !git-filter-repo fixes = log -1 --pretty=fixes - glog = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/glog\"" - https-and-ssh = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-https-and-ssh\"" + glog = "!git-zsh-autoload glog" + https-and-ssh = "!git-zsh-autoload https-and-ssh" ssh-and-https = https-and-ssh l = log - last-changed = "!cd \"$GIT_PREFIX\"; \"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-last-changed\"" - make-fork = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-make-fork\"" + last-changed = "!git-zsh-autoload last-changed" + make-fork = "!git-zsh-autoload make-fork" p = push - perm-stash = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-perm-stash\"" + perm-stash = "!git-zsh-autoload perm-stash" root = rev-parse --show-toplevel signoff = rebase --signoff ss = stash - ssync = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-ssync\"" - submodule-rm = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-submodule-rm\"" - track = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-track\"" + ssync = "!git-zsh-autoload ssync" + submodule-rm = "!git-zsh-autoload submodule-rm" + track = "!git-zsh-autoload track" branches = track [blame] date = short diff --git a/.config/git/zsh-autoload.sh b/.config/git/zsh-autoload.sh new file mode 100755 index 0000000..93b2093 --- /dev/null +++ b/.config/git/zsh-autoload.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# Copyright (c) 2025 Julian Prein +# +# Meant to be used in git aliases to launch an autoloadable zsh function in the +# correct directory. + +if [ $# -eq 0 ]; then + printf >&2 "Usage: $(basename "$0") \n" + exit 1 +fi + +BASE="${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git" + +# In git aliases, shell commands are executed from the top-level directory of +# the repo. GIT_PREFIX contains the original directory relative to the +# top-level. +[ -z "$GIT_PREFIX" ] || cd "$GIT_PREFIX" + +# no need for error handling, the message from sh is descriptive enough +if [ "${1#git-}" != "$1" ] || [ -e "$BASE/$1" ]; then + exec "$BASE/$@" +else + exec "$BASE/git-$@" +fi diff --git a/.local/bin/git-zsh-autoload b/.local/bin/git-zsh-autoload new file mode 120000 index 0000000..70bf9c9 --- /dev/null +++ b/.local/bin/git-zsh-autoload @@ -0,0 +1 @@ +../../.config/git/zsh-autoload.sh \ No newline at end of file