A couple more feature requests
Besides #11 , here's a couple more things I'd like to be able to do with xnotify:
- Add a property called "BAR" that displays a progress bar when given a value between 0 and 100. Combined with the "TAG" property, this would be nice to have with brightness/volume control scripts to get a quick visual representation of the relevant changes.
- Have a way to check notification history. Since xnotify reads from a FIFO, I'm aware this may not be possible to include within xnotify itself, so some examples on how to script this is greatly appreciated. Currently, I can think of a way to check history but I'd have to delete each entry to get to an older notification, which is not an ideal implementation.
I'd like to know your thoughts on these requests. If they're outside the scope of the project I totally understand.
Well, I ended up finding a way to achieve both through scripting.
- For bar drawing, I came up with this function in relevant scripts:
draw() {
perc=$1
size=$2
inc=$((perc * size / 100))
out=
for v in $(seq 0 $((size - 1))); do
test "$v" -le "$inc" &&
out="${out}${FULL}" ||
out="${out}${EMPTY}"
done
printf "%s" "$out"
}
- For history, its a bit uglier, I have to run two
xnotifyinstances using this script to query the notifications:
#!/usr/bin/sh
notif_log=/tmp/notif_hist
count=/tmp/notif_count
query() {
# Reverse order and attempts to dedup, doesnt work great
notifs=$(tac $notif_log | cat -n | sort -uk2 | sort -nk1 | cut -f2-)
if test $(find "$count" -mmin +1); then
rm $count
fi
if [ ! -f "$count" ]; then
echo 1 >$count
fi
c=$(cat $count)
echo "$notifs" | awk "NR==$c" >"$XNOTIFY_HIST_FIFO" &
c=$((c + 1))
echo "$c" >$count
}
cleanup() {
[ -f $count ] && rm $count
pkill -USR1 xnotify
}
case "$1" in
-c | --cleanup)
cleanup
;;
-q | --query | *)
query
;;
esac
And startup looks like this:
#!/usr/bin/env sh
if ! pgrep -x xnotify; then
rm -f $XNOTIFY_FIFO && rm -f $XNOTIFY_HIST_FIFO
mkfifo $XNOTIFY_FIFO && mkfifo $XNOTIFY_HIST_FIFO
tail -f $XNOTIFY_FIFO | tee -a /tmp/notif_hist | xnotify | sh &
xnotify 0<>$XNOTIFY_HIST_FIFO &
else
printf "xnotify is already running\n" >$XNOTIFY_FIFO
fi
I'm happy with the bar drawing, but the history setup could probably use some improvements.
Last commit added a BAR: flag to set the percentage (an integer between 0 and 100) of a progress bar to be drawn below the text.
On the history, you can invoke xnotify this way in your ~/.xinitrc:
XNOTIFY_FIFO="$HOME/.cache/xnotify$DISPLAY.fifo"
export XNOTIFY_FIFO
rm -f $XNOTIFY_FIFO
mkfifo $XNOTIFY_FIFO
cat -u 0<>$XNOTIFY_FIFO | tee -a $XNOTIFY_HISTORY | xnotify
The bar works great!! Thank you! Is it possible to change it's color?
In regards to history, is $XNOTIFY_HISTORY suppose to be the history file? If so, wont recalling history always come up with the last notification? I'm not sure what cat -u is suppose to do as it simply says "(ignored)" in the man page
Nevermind regarding history, it works great! Although I'm not quite sure how it works 🤔
In regards to history, is
$XNOTIFY_HISTORYsuppose to be the history file? If so, wont recalling history always come up with the last notification?
Yes, it is supposed to point to the history file.
Only new notifications will be piped into xnotify.
I'm not sure what
cat -uis suppose to do as it simply says "(ignored)" in the man page
It is needed for OpenBSD cat(1) but ignored on GNU cat(1). This option makes cat output new lines as soon as they are read (the output is unbuffered). The output for GNU cat is already unbuffered.
Ahh, that makes sense. Thanks for the clarification!