aboutsummaryrefslogtreecommitdiffstats
path: root/choose
blob: aa191e7c1b86a9b98fefebdb99cf59cbd4e00f15 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
### this script is meant to take a \n delimited list of things
### then give the user a way of selecting on of them.
### it should output the selection on a line by itself.
### and use $1 as the message to give to the user.
#message=$1
#shift
#sed 's|,|\\,|g;s|:|\\:|g' | tr '\n' ',' | rev | cut -b2- | rev | tr '\n' '\0' | xargs -0 xmessage -nearmouse "$@" "$message" -print -buttons
if [ "$1" ];then
 prompt="$1"
else
 prompt="< $0 >"
fi

if [ "${prompt}" != "${prompt:0:64}" ];then
  prompt="${prompt:0:64}..."
else
  prompt="${prompt}"
fi

if [ $DISPLAY ];then
#usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]
#             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]
  if which dmenu 2>&1 >/dev/null;then
  nb="$(xrdb -get choose.nb)"
  nf="$(xrdb -get choose.nf)"
  sb="$(xrdb -get choose.sb)"
  sf="$(xrdb -get choose.sf)"
  if [ "$nb" ];then nb="-nb $nb"; fi
  if [ "$nf" ];then nf="-nf $nf"; fi
  if [ "$sb" ];then sb="-sb $sb"; fi
  if [ "$sf" ];then sf="-sf $sf"; fi
    dmenu -l 10 -p "$prompt" $nb $nf $sb $sf
  else
    printf "dmenu missing. %s\n" "https://tools.suckless.org/dmenu/"
  fi
else
  if which pmenu 2>&1 >/dev/null; then
    pmenu -p "$prompt"
  else
    printf "pmenu missing. %s\n" "https://github.com/sgtpep/pmenu"
  fi
fi