summaryrefslogtreecommitdiff
path: root/scripts/.local/bin/selector
blob: cccd0a157600699b2f229829f5adaf43043b86e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

if [ -z "$DISPLAY" ]; then
   # if not running X11 -- bash prompt
   readarray -t items
   # display prompt text in stderr to not mix with selection output
   >&2 echo "$1"
   select item in "${items[@]}"; do
      echo ${item};
      break
   done < /dev/tty
else
   # X11 prompt with (possibly colored) dmenu
   dmenu="$(command -v cdmenu)"
   if [ -z "$dmenu" ]; then
      dmenu="dmenu"
   fi

   cat | $dmenu -p "$1"
fi