aboutsummaryrefslogtreecommitdiff
path: root/vis-open
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2025-01-05 18:55:14 +0100
committerRandy Palamar <randy@rnpnr.xyz>2025-01-06 07:38:01 -0700
commit824a7d19ae5bdc8eb6b3d61a591dc26d33ab3a38 (patch)
treef2e3f324011a852c04247e97caaf2110b7260611 /vis-open
parent75892aad7939b40354be7ea71bd55c651956b27c (diff)
downloadvis-824a7d19ae5bdc8eb6b3d61a591dc26d33ab3a38.tar.gz
vis-824a7d19ae5bdc8eb6b3d61a591dc26d33ab3a38.tar.xz
scripts: fix shellcheck warnings and make scripts more uniform
Diffstat (limited to 'vis-open')
-rwxr-xr-xvis-open28
1 files changed, 20 insertions, 8 deletions
diff --git a/vis-open b/vis-open
index 28d1b1a..bcd555a 100755
--- a/vis-open
+++ b/vis-open
@@ -5,13 +5,22 @@ set -e
NL='
'
-if [ -z "$VIS_OPEN_LINES" ]; then
- VIS_OPEN_LINES='0'
-fi
+fatal() {
+ echo "$@" >&2
+ exit 1
+}
-VIS_MENU_PROMPT=''
-ALLOW_AUTO_SELECT='1'
+usage() {
+ fatal "Usage: $(basename "$0") [-f] [-p prompt] [--] [file-pattern]
+
+Interactively select a file to open
+-f always present the given arguments, even when there is only one
+-p prompt
+file-pattern list of filenames and directories"
+}
+
+# print a list of filenames on stdin and distinguish directories
wrap_dirs() {
while read -r filename
do
@@ -23,6 +32,10 @@ wrap_dirs() {
done
}
+VIS_OPEN_LINES="${VIS_OPEN_LINES:-0}"
+VIS_MENU_PROMPT=''
+ALLOW_AUTO_SELECT='1'
+
while getopts fhp: opt; do
case "$opt" in
f)
@@ -31,9 +44,8 @@ while getopts fhp: opt; do
p)
VIS_MENU_PROMPT="$OPTARG"
;;
- h|?)
- printf 'usage: %s [-f] [-h] [-p prompt] [--] [file-pattern]\n' "${0##*/}"
- exit 0
+ *)
+ usage
;;
esac
done