Last active
December 23, 2023 03:41
-
-
Save vivien/9516784 to your computer and use it in GitHub Desktop.
i3blocks integration with dunst
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/sh | |
# | |
# i3blocks integration with dunst. | |
# Author: Vivien Didelot <[email protected]> | |
# | |
# 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 = FULL_PATH_OF_THIS_SCRIPT | |
# | |
# Add this block in your ~/.i3blocks.conf: | |
# | |
# [dunst] | |
# command=THIS_SCRIPT | |
# signal=12 | |
CACHE=~/.cache/i3blocks/notification | |
# Ensure the cache exists | |
mkdir -p `dirname $CACHE` | |
touch $CACHE | |
if env | grep -q BLOCK_ | |
then # called by i3blocks | |
# clear notification on click | |
test $BLOCK_BUTTON -ne 0 && cp /dev/null $CACHE | |
# source the notification | |
. $CACHE | |
FULL_TEXT="$SUMMARY $BODY" | |
SHORT_TEXT="$SUMMARY" | |
case $URGENCY in | |
LOW) | |
COLOR=#FFFFFF | |
CODE=0 | |
;; | |
NORMAL) | |
COLOR=#00FF00 | |
CODE=0 | |
;; | |
CRITICAL) | |
COLOR=#FF0000 | |
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+12 i3blocks | |
exit | |
fi | |
# vim: ts=2 sw=2 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @vivien,
In case you haven't heard, i3blocks is splitting into two repos! i3blocks will now go on to contain the core binary and a set of smallest usable blocklets to provide some beginner functionality. From i3blocks, i3blocks-contrib has now split off to gather the community contributed blocklets in a single repo to make perusing them easier and more convenient. We would be honoured if you would consider submitting your blocklet(s) to the contrib repo.
This change is the core change scheduled for the v1.5 release. Please note that as an artifact of this split, your entry for this blocklet in the core wiki has been removed as has everyone else's. If you would like to submit your blocklet, please review the contrib wiki to understand the workflow of i3blocks-contrib.
Please note that this change over is in its early stages, so the process for submission hasn't been completely nailed down. We're hard at work still compiling the two project wikis and documenting all changes and standards. It is very likely that things will still change and we value your input on how that change should occur.
Deepest regrads,
@Nycroth