summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlshprung <lshprung@yahoo.com>2021-04-15 17:08:12 -0700
committerlshprung <lshprung@yahoo.com>2021-04-15 17:08:12 -0700
commita312995bfebd7105e5b2c3e41d628136077212e8 (patch)
tree6930874c5029ef81fe1f3bce8ee2f546d8676898
First commit
-rw-r--r--README.md17
-rw-r--r--example.pngbin0 -> 8001 bytes
-rwxr-xr-xgraphical_prompt.sh26
3 files changed, 43 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..972f8aa
--- /dev/null
+++ b/README.md
@@ -0,0 +1,17 @@
+# graphical_prompt.sh
+
+graphical_prompt.sh is a shell script that uses zenity to create a graphical prompt before executing a given command. I originally wrote it to use as a logout prompt for openbox, but the script can be used to prompt before running any command.
+
+### Usage
+
+`graphical_prompt.sh COMMAND [PROMPT]`
+
+### Example
+
+The script can be used to prompt before shut down as follows:
+
+`graphical_prompt.sh "shutdown now" "Log Off and Shutdown?"`
+
+Running the above will generate the following prompt:
+
+![prompt](example.png)
diff --git a/example.png b/example.png
new file mode 100644
index 0000000..3c99895
--- /dev/null
+++ b/example.png
Binary files differ
diff --git a/graphical_prompt.sh b/graphical_prompt.sh
new file mode 100755
index 0000000..6b82104
--- /dev/null
+++ b/graphical_prompt.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+help_message() {
+ echo "Usage: $0 COMMAND [PROMPT_TEXT]"
+ echo "Example: $0 \"shutdown now\" \"Log Off and Shutdown?\""
+ exit
+}
+
+case $1 in
+ "" | "-h" | "--help" ) help_message;;
+esac
+
+PROMPT=$2
+if [ -z $2 ]; then
+ PROMPT="Are you sure?"
+fi
+echo $PROMPT
+zenity --question --text="$PROMPT"
+RES=$?
+
+# 0 -> YES
+# 1 -> NO
+
+if [ $RES -eq 0 ]; then
+ eval $1
+fi