summaryrefslogtreecommitdiff
path: root/scripts/gui/nsend
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2025-11-25 18:47:27 +0400
committerSuleyman Farajli <suleyman@farajli.net>2025-11-25 18:47:27 +0400
commitd947956270b092df10637bb3531441caca698b86 (patch)
tree8c32170ef044687b11be79398140a36430e2ff0a /scripts/gui/nsend
parentc388ade6b6d955138698731af02dfbe5c676439a (diff)
feat: new api for scripts
Diffstat (limited to 'scripts/gui/nsend')
-rwxr-xr-xscripts/gui/nsend56
1 files changed, 33 insertions, 23 deletions
diff --git a/scripts/gui/nsend b/scripts/gui/nsend
index 1bfc1f4..e1cbd78 100755
--- a/scripts/gui/nsend
+++ b/scripts/gui/nsend
@@ -1,34 +1,44 @@
#!/bin/sh
-. slib
+. "lib_common.sh"
+. "lib_handle.sh"
help() {
cat << EOF
-${0}: Wrapper script to send notifications
+${argv0}: Send notifications
options:
- -s [Name] [Msg] Send Msg with Name
- -s [Msg] Send Msg Without Name
+ -s [Msg] Send Msg
+ -t [Time] Disappear after Time (in second)
-h Print this message and exit
-EOF
+Note: time must be between 0 and 300,
+by default time is set to unlimited.
+EOF
exit 0
}
-case "${#}" in
-1)
- [ "${1}" = "-h" ] && help
- invalid_use
-;;
-2)
- [ "${1}" = "-s" ] || invalid_use
- notification_string="${2}"
-;;
-3)
- [ "${1}" = "-s" ] || invalid_use
- notification_string="${2}: ${3}"
-;;
-*) invalid_use ;;
-esac
-
-
-send_notification "${notification_string}"
+[ "${#}" -eq 0 ] && invalid_use
+
+time=-1
+while getopts "s:t:h" option; do
+ case "${option}" in
+ s) msg="${OPTARG}" ;;
+ t)
+ time="${OPTARG}"
+
+ case "${time}" in
+ ''|*[!0-9]*) err "Not a number: ${time}" ;;
+ esac
+
+ [ "${time}" -gt 300 ] && err "Out of range: ${time}"
+ ;;
+ h) help ;;
+
+ *) invalid_use -h ;;
+ esac
+done
+
+shift $((OPTIND - 1))
+[ ${#} != 0 ] && invalid_use
+
+notify_handle send "${time}" "${msg}"