Skip to content

Commit 60af048

Browse files
committed
termux-notification: add --help-actions
fixes #37
1 parent bb832a5 commit 60af048

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

scripts/termux-notification

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -e -u -f
44
SCRIPTNAME=termux-notification
55
show_usage () {
66
echo "Usage: termux-notification [options]"
7-
echo "Display a system notification. Content text is specified using -c/--content or read from stdin ."
7+
echo "Display a system notification. Content text is specified using -c/--content or read from stdin."
8+
echo "Please read --help-actions for help with action arguments."
89
echo " --action action action to execute when pressing the notification"
910
echo " --alert-once do not alert when the notification is edited"
1011
echo " --button1 text text to show on the first notification button"
@@ -16,6 +17,7 @@ show_usage () {
1617
echo " -c/--content content content to show in the notification. Will take precedence over stdin."
1718
echo " --group group notification group (notifications with the same group are shown together)"
1819
echo " -h/--help show this help"
20+
echo " --help-actions show the help for actions"
1921
echo " -i/--id id notification id (will overwrite any previous notification with the same id)"
2022
echo " --image-path path absolute path to an image which will be shown in the notification"
2123
echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)"
@@ -36,6 +38,28 @@ show_usage () {
3638
exit 0
3739
}
3840

41+
show_help_actions () {
42+
echo "This help refers to the arguments to options like --action, --on-delete, --button-1-action and --media-next."
43+
echo
44+
echo "All these commands take an action string as their argument, which is fed to \`dash -c\`."
45+
echo "A few important things must be kept in mind when using actions:"
46+
echo
47+
echo "You should use actions that do things outside of the terminal, like --action \"termux-toast hello\"."
48+
echo "Anything that outputs to the terminal is useless, so the output should either be redirected (--action \"ls > ~/ls.txt\") or shown to the user in a different way (--action \"ls|termux-toast\")."
49+
echo
50+
echo "Running more than one command in a single action is as easy as"
51+
echo "--action \"command1; command2; command3\""
52+
echo "or"
53+
echo "--action \"if [ -e file ]; then termux-toast yes; else termux-toast no; fi\"."
54+
echo
55+
echo "For anything more complex, you should put your script in a file, make it executable, and use that as the action:"
56+
echo "--action ~/bin/script"
57+
echo
58+
echo "The action is run in a different environment (not a subshell). Thus your environment is lost (most notably \$PATH), and ~/.profile is not sourced either. So if you need your \$PATH you should either:"
59+
echo " - if the action is a script, set it explicitly in the script (e.g. export PATH=\"\$HOME/bin:\$PATH\")"
60+
echo " - or use something like --action \"bash -l -c 'command1; command2'\")."
61+
}
62+
3963
OPT_ACTION=""
4064
OPT_ALERT_ONCE=""
4165
OPT_BUTTON1_ACTION=""
@@ -70,7 +94,7 @@ TEMP=`busybox getopt \
7094
button1:,button1-action:,\
7195
button2:,button2-action:,\
7296
button3:,button3-action:,\
73-
content:,group:,help,id:,image-path:\
97+
content:,group:,help,help-actions,id:,image-path:\
7498
led-color:,led-on:,led-off:,\
7599
media-previous:,media-next:,media-play:,media-pause:,\
76100
on-delete:,ongoing,\
@@ -93,6 +117,7 @@ while true; do
93117
-c | --content) OPT_CONTENT="$2"; shift 2;;
94118
--group) OPT_GROUP="$2"; shift 2;;
95119
-h | --help) show_usage;;
120+
--help-actions) show_help_actions; exit 0;;
96121
-i | --id) OPT_ID="$2"; shift 2;;
97122
--image-path) OPT_IMAGE_PATH="$2"; shift 2;;
98123
--led-color) OPT_LED_COLOR="$2"; shift 2;;

0 commit comments

Comments
 (0)