aboutsummaryrefslogtreecommitdiff
path: root/vis-open
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-07-10 17:56:28 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-07-10 18:03:24 +0200
commita657e8499ab04bf8b9b4ffcb954acee574d239a1 (patch)
tree7aa7af07677a5b24955230e9da2d708b8abb1ec3 /vis-open
parent29b718e1d2b94f95281911c80ec5460cbd7fc526 (diff)
downloadvis-a657e8499ab04bf8b9b4ffcb954acee574d239a1.tar.gz
vis-a657e8499ab04bf8b9b4ffcb954acee574d239a1.tar.xz
vis: add a file open dialog
For this to work make sure you have vis-open and slmenu or dmenu somewhere in $PATH. For now the file dialog is shown for :open, :split and :vsplit when the argument is either . (a dot) or looks like a file pattern. For example :open *.[ch] will show a listing of all C source and header files in the current directory. Use a fuzzy search to make your choice.
Diffstat (limited to 'vis-open')
-rwxr-xr-xvis-open47
1 files changed, 47 insertions, 0 deletions
diff --git a/vis-open b/vis-open
new file mode 100755
index 0000000..0bcdd5c
--- /dev/null
+++ b/vis-open
@@ -0,0 +1,47 @@
+#!/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: $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"
+ exit 1
+ fi
+fi
+
+DIR=""
+
+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