vis: enhance <C-v> to recognize a few special keys
[vis.git] / vis-open
bloba47249f8330f91deaeda54225e610981dbef1e0a
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: $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"
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