Skip to content

Instantly share code, notes, and snippets.

@amygrinn
Last active October 24, 2021 14:35
Show Gist options
  • Save amygrinn/d1409ad7e9bf19f995f76882f13fb1a8 to your computer and use it in GitHub Desktop.
Save amygrinn/d1409ad7e9bf19f995f76882f13fb1a8 to your computer and use it in GitHub Desktop.
Libnotify shim for termux
#!/bin/bash
# This is a shim for libnotify on termux.
# Calls termux-notification with translated arguments from notify-send
ARGS=""
POSITIONAL=()
while [[ $# -gt 0 ]]; do
case "$1" in
-i|--icon)
ARGS+="--image-path $2 "
shift # past argument
shift # past value
;;
-t|--expire-time)
if [[ $2 == 0 ]]; then
ARGS+="--ongoing "
fi
shift # past argument
shift # past value
;;
-c|--category)
ARGS+="--group $2 "
shift # past argument
shift # past value
;;
-u|--urgency)
case "$2" in
critical)
ARGS+="--priority max ";;
normal)
ARGS+="--priority default ";;
low)
ARGS+="--priority low ";;
esac
shift # past argument
shift # past value
;;
--app-name)
# ignore
shift # past argument
shift # past value
;;
-h|--hint)
if [[ $2 =~ ^string:(x-canonical-)?(private-)?(synchronous|x-dunst-stack-tag):(.*)$ ]]; then
ARGS+="--id ${BASH_REMATCH[-1]} "
fi
if [[ $2 =~ ^string:termux-action:(.*)$ ]]; then
ARGS+="--action '${BASH_REMATCH[-1]}' "
fi
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
if [ 2 == ${#POSITIONAL[@]} ]; then
ARGS+="--title \"${POSITIONAL[0]}\" "
ARGS+="--content \"${POSITIONAL[1]}\" "
else
ARGS+="--content \"${POSITIONAL[0]}\" "
fi
echo $ARGS | xargs termux-notification
@erikLundstedt
Copy link

that looks super cool

@amygrinn
Copy link
Author

Thanks

@erikLundstedt
Copy link

apparently i have set your gists as an rss feed in my rss reader
have you done anything realated to emacs,lisp,computercraft or linux(like have you added any general purpose scripts on gist)
i dont remember adding it

glad i did though
cheers

@erikLundstedt
Copy link

it might be that you made is-plural.el which was recently shared on a discord server i frequent

@amygrinn
Copy link
Author

Thanks! I actually wrote this script to complement an emacs package I'm working on, https://gitlab.com/tygrdev/org-yaap . It's not fully ready yet though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment