From a657e8499ab04bf8b9b4ffcb954acee574d239a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 10 Jul 2015 17:56:28 +0200 Subject: 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. --- vis-open | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 vis-open (limited to 'vis-open') 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 -- cgit v1.2.3