-
Notifications
You must be signed in to change notification settings - Fork 1
/
dopt.sh
executable file
·33 lines (27 loc) · 972 Bytes
/
dopt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
##
# "dialog option" - meant to be used as a filter / pipeline for graphically
# selecting *multiple* items from standard input.
#
# PLEASE BE AWARE THAT QUOTING ISSUES ARE NOT TAKEN INTO CONSIDERATION!!!
#
# If you are not careful, spaces in filenames will really ruin your day.
#
# vim -o `ls *.txt | dmenu.sh`
##
# get stdin
ALL=`cat`
# number the lines
SPLITTED=$( echo $ALL | sed 's/ /\n/g' | awk -- '{print NR, $0, 0 }' )
# prompt via dialog (output-fd=1 is so that dialog gui doesn't go to subshell)
OUT=$(dialog --output-fd 1 --ok-label Select --separate-output --checklist Choose 0 50 22 $SPLITTED)
EXIT_CODE=$?
# handle escape / cancel buttons
if [ "1" = "$EXIT_CODE" ] ; then exit 1 ; fi
if [ "255" = "$EXIT_CODE" ] ; then exit 1 ; fi
# loop through selected numbers
for X in $OUT ; do
# inefficiently print out the text corresponding to the selections
CHOSEN=$( echo $ALL | sed 's/ /\n/g' | awk -- "NR==$X {print \$0 }" )
echo $CHOSEN
done;