Re: [dwm] Notifications

From: Carlos Pita <carlosjosepita_AT_gmail.com>
Date: Mon, 29 Sep 2008 21:01:42 -0300

> How about using dzen[1]?

I didn't know about it, thanks for the advice.

I've wrote a simple bash script that takes care of wrapping long lines
and dynamically adjust the notification window width according to the
longest line and the current font (using the provided textwidth
utility). Maybe someone else will find it useful.

#!/bin/sh

FONT=-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*
WIDTH=40
COLORS="-bg black -fg red"
SCREEN_WIDTH=1280
TIMEOUT=8

if [[ -z $1 ]]
then
    echo "Usage: notify title_line [other_line...]"
    exit 1
fi

pkill dzen2 # kill previous notification
text=$1
if [[ -n $2 ]]
then
    body=`echo $2 | fold -s -w $WIDTH`
    text="$text
$body"
fi
lm=(`echo "$text" | awk -v font=$FONT 'BEGIN { max = 0; } {
("textwidth " font " \"" $0 "\"") | getline cur; if (cur > max) { max
= cur } } END { print (NR-1) " " (max+20) }'`)
if ((lm[0] > 0))
then
    larg="-l ${lm[0]}"
fi
warg="-w ${lm[1]}"
xarg="-x $((SCREEN_WIDTH - lm[1]))"
echo "$text" | dzen2 -p $TIMEOUT $xarg -y 0 $warg $larg -bg black -fg
red -fn $FONT -e "onstart=uncollapse;button3=exit"&

exit 0

Regards
-Carlos
Received on Tue Sep 30 2008 - 00:01:42 UTC

This archive was generated by hypermail 2.2.0 : Tue Sep 30 2008 - 00:12:04 UTC