Files
dotfiles/.config/git/external-script.sh
Julian Prein 6db1a710c6 git: Rename zsh-autoload.sh -> external-script.sh
With the last commit 9c1e3f4679 (git:zsh-autoload: Use relative
scripts/ folder, 2025-09-12), `zsh-autoload.sh` could execute any type
of external script. Rename it to a more generic name.
2025-09-12 16:25:39 +02:00

29 lines
813 B
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Julian Prein
#
# Meant to be used by git aliases to easily launch an external script from the
# ./scripts/ collection through its basename and in the correct directory (i.e.
# GIT_PREFIX).
if [ $# -eq 0 ]; then
printf >&2 "Usage: %s <function>\n" "$(basename "$0")"
exit 1
fi
name="$1"
shift
BASE="$(dirname "$(realpath "$0")")/scripts"
# 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" || exit
# no need for error handling, the message from sh is descriptive enough
if [ "${name#git-}" != "$name" ] || [ -e "$BASE/$name" ]; then
exec "$BASE/$name" "$@"
else
exec "$BASE/git-$name" "$@"
fi