aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-06-22 09:17:52 -0300
committerEuAndreh <eu@euandre.org>2021-06-22 09:18:06 -0300
commit0ee2ce2c85d3376b35dc9338309e50e3c6f9eb80 (patch)
tree90a9266df106a7146796b955d5c70cbb2dab7605
parentTODOs.md: Add #task-bebbe847-f552-be4b-b886-70a621162b69 (diff)
downloadgit-permalink-0ee2ce2c85d3376b35dc9338309e50e3c6f9eb80.tar.gz
git-permalink-0ee2ce2c85d3376b35dc9338309e50e3c6f9eb80.tar.xz
src/git-permalink.sh: Use getopts, handle "--" somewhat
See #task-bebbe847-f552-be4b-b886-70a621162b69.
-rwxr-xr-xsrc/git-permalink.sh45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/git-permalink.sh b/src/git-permalink.sh
index 3b9a466..e5fa27a 100755
--- a/src/git-permalink.sh
+++ b/src/git-permalink.sh
@@ -97,26 +97,39 @@ version() {
}
PRINTONLY=false
-if [ "${1:-}" = '-p' ]; then
- PRINTONLY=true
- shift
-fi
-if [ -z "${1:-}" ]; then
- printf '%s\n\n' "$MSG_MISSING_FILE" >&2
- usage >&2
- exit 2
-fi
-FILE="$1"
+while getopts 'phV' flag; do
+ case "$flag" in
+ p)
+ PRINTONLY=true
+ shift
+ ;;
+ h)
+ usage
+ help
+ exit
+ ;;
+ V)
+ version
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
# shellcheck disable=2068
for flag in $@; do
case "$flag" in
- -h|--help)
+ --)
+ shift
+ break
+ ;;
+ --help)
usage
help
exit
;;
- -V|--version)
+ --version)
version
exit
;;
@@ -125,7 +138,13 @@ for flag in $@; do
esac
done
-FILE="${1:-}"
+if [ -z "${1:-}" ]; then
+ printf '%s\n\n' "$MSG_MISSING_FILE" >&2
+ usage >&2
+ exit 2
+fi
+
+FILE="$1"
MYLINENO="${2:-}"
COMMIT="$(git rev-parse HEAD)"
ORIGIN="$(git config remote.origin.url)"