vis-lua: expose currently active key bindings through API
[vis.git] / vis-open
blob997aa49730ac342252ccd391bcba5d5b521ece55
1 #!/bin/sh
2 set -e
4 # Later, we're going to want to set $IFS to a single newline, so let's prepare one.
5 NL='
8 VIS_MENU_PROMPT=""
9 ALLOW_AUTO_SELECT=1
11 while [ $# -gt 0 ]; do
12 case "$1" in
13 -h|--help)
14 echo "usage: $(basename $0) [-h] [-p prompt] [-f] [--] [file-pattern]"
15 exit 0;
17 -p)
18 VIS_MENU_PROMPT=$2
19 shift
20 shift
22 -f)
23 ALLOW_AUTO_SELECT=""
24 shift
26 --)
27 shift
28 break
31 break
33 esac
34 done
36 # At this point, all the remaining arguments should be the expansion of
37 # any globs that were passed on the command line.
39 if [ $# -eq 1 -a "$ALLOW_AUTO_SELECT" = 1 ]; then
40 # If there were globs on the command-line, they've expanded to
41 # a single item, so we can just process it.
43 if [ -d "$1" ]; then
44 # Recurse and show the contents of the named directory,
45 # We pass -f to force the next iteration to present the
46 # full list, even if it's just an empty directory.
47 cd "$1"
48 IFS=$NL # Don't split ls output on tabs or spaces.
49 exec "$0" -p "$VIS_MENU_PROMPT" -f .. $(ls -1)
50 else
51 # We've found a single item, and it's not a directory,
52 # so it must be a filename (or file-like thing) to open.
53 cd "$(dirname "$1")"
54 echo "$(pwd -P)"/"$(basename "$1")"
55 exit 0
59 # At this point, we have a bunch of options we need to present to the
60 # user so they can pick one.
61 CHOICE=$(printf "%s\n" "$@" | vis-menu -b -p "$VIS_MENU_PROMPT")
63 # Did they pick a file or directory? Who knows, let's let the next iteration figure it out.
64 exec "$0" -p "$VIS_MENU_PROMPT" -- "$CHOICE"