diff options
Diffstat (limited to 'src/git-permalink.sh')
-rwxr-xr-x | src/git-permalink.sh | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/src/git-permalink.sh b/src/git-permalink.sh index 11da86b..12f9fc8 100755 --- a/src/git-permalink.sh +++ b/src/git-permalink.sh @@ -4,7 +4,9 @@ set -eu FILE="${1:-}" MYLINENO="${2:-}" COMMIT="$(git rev-parse HEAD)" -ORIGIN="$(git config --get remote.origin.url)" +ORIGIN="$(git config remote.origin.url)" +OVERRIDE_CF="$(git config git-permalink.template-commit-file ||:)" +OVERRIDE_FC="$(git config git-permalink.template-file-commit ||:)" REPOSITORY="$(basename "$PWD")" usage() { @@ -93,27 +95,34 @@ github() { } guess_permalink() { - case "$ORIGIN" in - *euandreh.xyz*) - euandreh - ;; - *git.sr.ht*) - sourcehut - ;; - *git.savannah.gnu.org*) - savannah - ;; - *gitlab.com*) - gitlab - ;; - *github.com*) - github - ;; - *) - echo "Unsupported origin: $ORIGIN" >&2 - exit 1 - ;; - esac + if [ -n "$OVERRIDE_CF" ]; then + printf "$OVERRIDE_CF\n" "$COMMIT" "$FILE" + elif [ -n "$OVERRIDE_FC" ]; then + printf "$OVERRIDE_FC\n" "$FILE" "$COMMIT" + else + case "$ORIGIN" in + *euandreh.xyz*) + euandreh + ;; + *git.sr.ht*) + sourcehut + ;; + *git.savannah.gnu.org*) + savannah + ;; + *gitlab.com*) + gitlab + ;; + *github.com*) + github + ;; + *) + printf "Unsupported origin: %s.\n\n" $ORIGIN >&2 + printf 'Add an template override to use git-permalink (see "man git-permalink.1" for instructions).\n' >&2 + exit 1 + ;; + esac + fi } LINK="$(guess_permalink)" |