forked from martanne/vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vis-open
executable file
·48 lines (43 loc) · 852 Bytes
/
vis-open
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
PATTERN="."
[ -z "$VIS_MENU" ] && VIS_MENU="slmenu"
[ -z "$VIS_MENU_ARGS" ] && VIS_MENU_ARGS="-b"
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
echo "usage: $(basename $0) [-h] [-p prompt] [file-pattern]"
exit 0;
;;
-p)
VIS_MENU_ARGS="$VIS_MENU_ARGS -p $2"
shift
shift
;;
*)
PATTERN=$*
break
;;
esac
done
if ! type "$VIS_MENU" >/dev/null 2>&1; then
if [ ! -z "$DISPLAY" ] && type "dmenu" >/dev/null 2>&1; then
VIS_MENU="dmenu"
else
echo "Neither slmenu nor dmenu found" >&2
exit 1
fi
fi
DIR=""
[ ! -z "$PATTERN" -a "$PATTERN" != "." -a -d "$PATTERN" ] && DIR="$PATTERN"
while true; do
SEL=$({ echo ..; ls -1 $PATTERN; } | $VIS_MENU $VIS_MENU_ARGS)
[ -z "$SEL" ] && exit 1
[ ! -z "$DIR" ] && SEL="$DIR/$SEL"
if [ -d "$SEL" ]; then
DIR="$SEL"
PATTERN="$DIR"
else
echo "$SEL"
exit 0
fi
done