4 # Later, we're going to want to set $IFS to a single newline, so let's prepare one.
8 if [ -z "$VIS_OPEN_LINES" ]; then
16 while read -r filename
18 if [ -d "$filename" ]; then
19 printf '%s/\n' "$filename"
21 printf '%s\n' "$filename"
26 while getopts fhp
: opt
; do
32 VIS_MENU_PROMPT
="$OPTARG"
35 printf 'usage: %s [-f] [-h] [-p prompt] [--] [file-pattern]\n' "${0##*/}"
40 shift "$((OPTIND - 1))"
42 # At this point, all the remaining arguments should be the expansion of
43 # any globs that were passed on the command line.
45 if [ "$#" -eq 1 ] && [ "$ALLOW_AUTO_SELECT" = '1' ]; then
46 # If there were globs on the command-line, they've expanded to
47 # a single item, so we can just process it.
50 # Recurse and show the contents of the named directory,
51 # We pass -f to force the next iteration to present the
52 # full list, even if it's just an empty directory.
54 IFS
="$NL" # Don't split ls output on tabs or spaces.
55 exec "$0" -p "$VIS_MENU_PROMPT" -f "$(ls -1)"
57 # We've found a single item, and it's not a directory,
58 # so it must be a filename (or file-like thing) to open,
59 # unless the parent directory does not exist.
60 parentdir
="$(dirname -- "$1")"
61 if [ -d "$parentdir" ]; then
63 printf '%s/%s\n' "$(pwd -P)" "$(basename -- "${1%\*}")"
71 # At this point, we have a bunch of options we need to present to the
72 # user so they can pick one.
73 CHOICE
="$(printf '%s\n' '..' "$@
" | wrap_dirs | vis-menu -b -l "$VIS_OPEN_LINES" -p "$VIS_MENU_PROMPT")"
75 # Did they pick a file or directory? Who knows, let's let the next iteration figure it out.
76 exec "$0" -p "$VIS_MENU_PROMPT" -- "$CHOICE"