aboutsummaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-03-04 22:45:16 +0100
committerPatrick Spek <p.spek@tyil.nl>2021-08-14 11:59:32 +0200
commit06683b22c139a8ebf637256fad1a79734d872964 (patch)
tree660f72dfd4c102bc3b5562e10afcfd9ff467256c /.local
parent3c1cb11bbe79728aea755dbdb6c6751f60955c98 (diff)
Add path utility
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/path49
1 files changed, 49 insertions, 0 deletions
diff --git a/.local/bin/path b/.local/bin/path
new file mode 100755
index 0000000..a3a6517
--- /dev/null
+++ b/.local/bin/path
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+
+main()
+{
+ # Handle opts
+ while getopts ":h" opt
+ do
+ case "$opt" in
+ h) usage && exit 0 ;;
+ *)
+ printf "Invalid option passed: %s\n" "$OPTARG" >&2
+ ;;
+ esac
+ done
+
+ shift $(( OPTIND - 1 ))
+
+ PATHVAR="${1:-PATH}"
+
+ printf "%s" "${!PATHVAR}" | sed 's/:/\n/g'
+ printf "\n"
+}
+
+usage()
+{
+ cat <<EOF
+Usage:
+ ${0##*/} -h
+ ${0##*/} [PATHVAR]
+
+Print a PATHVAR as a human-readable list of paths. If PATHVAR is not given, it
+will default to PATH.
+
+Options:
+ -h Show this help text and exit.
+EOF
+}
+
+main "$@"