Last active
October 24, 2021 14:35
-
-
Save amygrinn/d1409ad7e9bf19f995f76882f13fb1a8 to your computer and use it in GitHub Desktop.
Libnotify shim for termux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.