Skip to content

Commit

Permalink
vis: introduce vis-menu helper script
Browse files Browse the repository at this point in the history
This serves as a wrapper around dmenu(1) and slmenu(1), by default
the latter is preferred because it also works without an X server.

The program and its default arguments can be configured by means of
the $VIS_MENU and $VIS_MENU_ARGS environment variables.

Eventually we might decide to inlcude a stripped down version of
slmenu in the vis source tree.
  • Loading branch information
martanne committed May 16, 2016
1 parent 66d7f9e commit 66ca702
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ install: vis
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f vis ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/vis
@cp -f vis-menu ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/vis-menu
@cp -f vis-open ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/vis-open
@cp -f vis-clipboard ${DESTDIR}${PREFIX}/bin
Expand Down
33 changes: 33 additions & 0 deletions vis-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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: $(basename $0) [-h] [-p prompt]"
exit 0;
;;
-p)
VIS_MENU_ARGS="$VIS_MENU_ARGS -p $2"
shift
shift
;;
*)
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" >&2
exit 1
fi
fi

exec $VIS_MENU $VIS_MENU_ARGS
14 changes: 2 additions & 12 deletions vis-open
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/sh

PATTERN="."
[ -z "$VIS_MENU" ] && VIS_MENU="slmenu"
[ -z "$VIS_MENU_ARGS" ] && VIS_MENU_ARGS="-b"
VIS_MENU_ARGS=""

while [ $# -gt 0 ]; do
case "$1" in
Expand All @@ -22,20 +21,11 @@ while [ $# -gt 0 ]; do
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" >&2
exit 1
fi
fi

DIR=""
[ ! -z "$PATTERN" -a "$PATTERN" != "." -a -d "$PATTERN" ] && DIR="$PATTERN"

while true; do
SEL=$({ echo ..; ls -1 $PATTERN 2>/dev/null || echo $PATTERN; } | $VIS_MENU $VIS_MENU_ARGS)
SEL=$({ echo ..; ls -1 $PATTERN 2>/dev/null || echo $PATTERN; } | vis-menu $VIS_MENU_ARGS)
[ -z "$SEL" ] && exit 1
[ ! -z "$DIR" ] && SEL="$DIR/$SEL"
if [ -d "$SEL" ]; then
Expand Down

0 comments on commit 66ca702

Please sign in to comment.