Created
December 9, 2016 02:02
-
-
Save craftyguy/e36f816e4f6d163e461dbc03c93d5817 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# i3blocks integration with dunst. | |
# Author: Vivien Didelot <[email protected]> | |
# ~/.config/dunst/notify | |
# dunst caches a notification and signals i3blocks. | |
# i3blocks catches the signal and prints the cached notification. | |
# | |
# Put this rule at the end of your ~/.config/dunst/dunstrc: | |
# | |
# [i3blocks] | |
# summary = "*" | |
# script = ~/.config/dunst/notify | |
# | |
# Add this block in your ~/.i3blocks.conf: | |
# | |
# [dunst] | |
# command=THIS_SCRIPT | |
# signal=12 | |
CACHE=~/.cache/i3blocks/notification | |
NOTIFY_TIMEOUT=30 | |
# Ensure the cache exists | |
mkdir -p `dirname $CACHE` | |
touch $CACHE | |
function clear_notification(){ | |
cp /dev/null $CACHE | |
. $CACHE | |
pkill -RTMIN+3 i3blocks | |
exit | |
} | |
if env | grep -q BLOCK_ | |
then # called by i3blocks | |
# clear notification on click | |
test $BLOCK_BUTTON -ne 0 && clear_notification | |
# source the notification | |
. $CACHE | |
if [[ $APPNAME == *"Clementine"* ]]; then | |
T_ICON=" " | |
elif [[ $SUMMARY == *"pass"* ]]; then | |
T_ICON=" " | |
else | |
T_ICON=" " | |
fi | |
SHORT_TEXT=" $SUMMARY " | |
FULL_TEXT=" $T_ICON $SUMMARY: $BODY " | |
case $URGENCY in | |
LOW) | |
COLOR=#7D6506 | |
CODE=0 | |
;; | |
NORMAL) | |
COLOR=#7D6506 | |
CODE=0 | |
;; | |
CRITICAL) | |
COLOR=#f297a8 | |
CODE=33 | |
;; | |
*) | |
# unknown urgency, certainly empty notification | |
exit 0 | |
;; | |
esac | |
# Output the status block | |
echo $FULL_TEXT | |
echo $SHORT_TEXT | |
echo $COLOR | |
exit $CODE | |
else # called by dunst | |
# store the notification | |
cat << dunst > $CACHE | |
APPNAME="$1" | |
SUMMARY="$2" | |
BODY="$3" | |
ICON="$4" | |
URGENCY="$5" | |
dunst | |
# signal i3blocks that there is a new notification | |
pkill -RTMIN+3 i3blocks | |
fi | |
sleep $NOTIFY_TIMEOUT | |
clear_notification | |
# vim: ts=2 sw=2 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment