aboutsummaryrefslogtreecommitdiff
path: root/src/git-permalink.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/git-permalink.sh')
-rwxr-xr-xsrc/git-permalink.sh29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/git-permalink.sh b/src/git-permalink.sh
index f664b9e..d861ccd 100755
--- a/src/git-permalink.sh
+++ b/src/git-permalink.sh
@@ -1,14 +1,6 @@
#!/bin/sh
set -eu
-FILE="${1:-}"
-MYLINENO="${2:-}"
-COMMIT="$(git rev-parse HEAD)"
-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() {
printf 'Usage: %s [-p] FILE [LINENO]\n' "$0"
}
@@ -27,13 +19,18 @@ version() {
echo 'git-permalink-@VERSION@ @DATE@'
}
-if [ -z "$FILE" ]; then
+PRINTONLY=false
+if [ "${1:-}" = '-p' ]; then
+ PRINTONLY=true
+ shift
+fi
+if [ -z "${1:-}" ]; then
printf "Missing \$FILE argument\n\n" >&2
usage >&2
exit 2
fi
+FILE="$1"
-PRINTONLY=false
# shellcheck disable=2068
for flag in $@; do
case "$flag" in
@@ -46,15 +43,19 @@ for flag in $@; do
version
exit
;;
- -p)
- PRINTONLY=true
- shift
- ;;
*)
;;
esac
done
+FILE="${1:-}"
+MYLINENO="${2:-}"
+COMMIT="$(git rev-parse HEAD)"
+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")"
+
euandreh() {
printf 'https://git.euandreh.xyz/%s/tree/%s?id=%s%s\n' "$REPOSITORY" "$FILE" "$COMMIT" "${MYLINENO:+#n$MYLINENO}"
}