-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprompt
executable file
·40 lines (34 loc) · 900 Bytes
/
prompt
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
#!/bin/sh
# For example:
# `./prompt "Do you want to shutdown?" \
# && shutdown -h now || echo "Dose not turn off"`
YES="Yes"; NO="No"
_dmenu() {
dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray;
}
main() {
[ "$(printf "$NO\\n$YES" | _dmenu "$1" )" = "$YES" ] || exit 1
}
_usage() {
echo "$ prompt [options] <Prompt>"
echo ""
echo "Yes/No prompt using dmenu."
echo "Exits with value 0 if Yes and 1 if No."
echo ""
echo "options:"
echo " -h, --help print this message"
echo ""
echo "Example:"
echo " $ ./prompt \"Do you want to shutdown?\" \\"
echo " && shutdown -h now || echo \"Dose not turn off\""
}
# Read arguments
POSITIONAL=()
while [[ $# -gt 0 ]]; do
case $1 in
-h|-?|--help) _usage; exit 0 ;;
-*) echo "Invalid option '$1'" > /dev/stderr; exit 1 ;;
*) POSITIONAL+=("$1") ;;
esac; shift;
done
main "${POSITIONAL[@]}"