Add simple prompt program based on dmenu

Can be used to as for confirmation for actions (E.g. shut down pc,
reboot and so on). Takes 3 parameters, with the last being optional, in
the form of:

dmenuprompt "Text to display" "command to execute on yes"
[success/warn/danger]

The last flag only changes the colors being displayed by the prompt.
If the last flag is not provided, it will display in default colors.
This commit is contained in:
Marty Oehme 2019-05-22 14:24:29 +02:00
parent 0e829a629c
commit 472b2e8f92

15
.config/scripts/bin/dmenuprompt Executable file
View file

@ -0,0 +1,15 @@
#!/bin/sh
# A dmenu binary prompt script.
# Gives a dmenu prompt labeled with $1 to perform command $2.
# For example:
# `./prompt "Do you want to shutdown?" "shutdown -h now"`
if [[ -z $3 ]] || [[ $3 == "normal" ]]; then
[ "$(printf "No\\nYes" | dmenu -i -p "$1")" = "Yes" ] && $2
elif [[ $3 == "success" ]]; then
[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb webgreen -sb greenyellow -sf black -nf white )" = "Yes" ] && $2
elif [[ $3 == "warn" ]] || [[ $3 == "warning" ]]; then
[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb goldenrod -sb gold -sf black -nf white )" = "Yes" ] && $2
elif [[ $3 == "danger" ]]; then
[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray )" = "Yes" ] && $2
fi