In git aliases, shell commands are executed from the top-level directory of the repo. Because of this, something like `git glog -- file` didn't work in subdirectories. Fix this by creating a wrapper script that first changes into $GIT_PREFIX before executing the script. Since (currently) the only use-case is to launch the functions in `autoload/git/`, most of the path could move into the script, making the git config a lot cleaner.
26 lines
699 B
Bash
Executable File
26 lines
699 B
Bash
Executable File
#!/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") <function>\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
|