vis: let ~ have an immediate effect in normal mode
[vis.git] / vis-open
blobd516ff1444b0db805e133f25e2cd43e82d551a28
1 #!/bin/sh
3 PATTERN="."
4 [ -z "$VIS_MENU" ] && VIS_MENU="slmenu"
5 [ -z "$VIS_MENU_ARGS" ] && VIS_MENU_ARGS="-b"
7 while [ $# -gt 0 ]; do
8 case "$1" in
9 -h|--help)
10 echo "usage: $(basename $0) [-h] [-p prompt] [file-pattern]"
11 exit 0;
13 -p)
14 VIS_MENU_ARGS="$VIS_MENU_ARGS -p $2"
15 shift
16 shift
19 PATTERN=$*
20 break
22 esac
23 done
25 if ! type "$VIS_MENU" >/dev/null 2>&1; then
26 if [ ! -z "$DISPLAY" ] && type "dmenu" >/dev/null 2>&1; then
27 VIS_MENU="dmenu"
28 else
29 echo "Neither slmenu nor dmenu found" >&2
30 exit 1
34 DIR=""
35 [ ! -z "$PATTERN" -a "$PATTERN" != "." -a -d "$PATTERN" ] && DIR="$PATTERN"
37 while true; do
38 SEL=$({ echo ..; ls -1 $PATTERN; } | $VIS_MENU $VIS_MENU_ARGS)
39 [ -z "$SEL" ] && exit 1
40 [ ! -z "$DIR" ] && SEL="$DIR/$SEL"
41 if [ -d "$SEL" ]; then
42 DIR="$SEL"
43 PATTERN="$DIR"
44 else
45 echo "$SEL"
46 exit 0
48 done