HLWM with B.A.R - GNU/Linux

Users browsing this thread: 1 Guest(s)
Long time nixers
By default hlwm uses dzen2, while nice (and clickable) I've always found the positioning and usage of multiple instances to get what you want annoying.

So when I moved to Herbstluftwm it was the first thing to go.

Now the issue is the default panel script is made especially for dzen2 so in my case I just started with a new script entirely.

Here are some useful functions I've made along the way:

#!/usr/bin/env bash


timeicon="$iconcolor ¶ $stop"
musicicon="$iconcolor ê $stop"
volumelicon="$iconcolor ì $stop"
volumehicon="$iconcolor í $stop"
muteicon="$iconcolor ë $stop"
mailicon="$iconcolor Ì $stop"
nomailicon="$iconcolor Ë $stop"
wifiicon="$iconcolor ­ $stop"    # Yes, there is an icon here.
nowifiicon="$iconcolor µ $stop"
ircicon="$iconcolor § $stop"

function mpcs(){
    mpcheck=$(mpc status | grep '#')
    notags=$(mpc current -f "%artist%")
    if [ ! "$mpcheck" ]
        echo -n "$musicicon "
        echo -n "\f9No Track\fr" " \f7- " "\f2Playing\fr" "\f50:00/0:00"
    elif [ ! "$notags" ]
        echo -n "$musicicon "
        echo -n "\f9"
        mpc current -f "%file%" | sed 's/Various Artists\/Mix\///;s/\.mp3//;s/-/\\fr\\f7-\\f2/'
        echo -n "$musicicon "
        echo -n "\f9"
        mpc current -f "%artist%"
        echo -n "\fr"
        echo -n "\f7- "
        echo -n "\f2"
        mpc current -f "%title%"

function irc(){
    im=$(tail -n 1 ~/.weechat/logs/events | sed 's/USERNAME: //;s/.*highlight./\\f7(/;s/|/)\\f9 /;s/\+/\\f4+\\f7/' | cut -c1-50)
    if [ ! $(pidof weechat-curses) ]
        echo -n "$ircicon" "(IRC) Disconnected"
        echo -n "$ircicon" "${im}"

function clock(){
    date +"\f9%m/%d/%y $timeicon\f2 %l:%M %p"

function volume(){
    vollevel=$(amixer get Master | tail -n 1 | cut -d '[' -f 2 | sed 's/%.*//g' | sed -n 1p)
    case 1 in
        $(($vollevel== 0))) echo -n "$muteicon" "" $vollevel ;;
        $(($vollevel<= 69))) echo -n "$volumelicon" "" $vollevel ;;
        $(($vollevel>= 70))) echo -n "$volumehicon" "" $vollevel ;;

function network(){
    up=$(ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo "ok" || echo "error")
    #ssid=$(nmcli dev wifi|grep yes| cut -d\' -f2)
    case 1 in
        $(($up== "error"))) echo -n "$nowifiicon" ;;
        $(($up== "ok"))) echo -n "$wifiicon" ;;
        $(( ! $up))) echo -n "$ircicon" ;;

function mail(){
    getmail=$(curl -u USER@gmail.com:PASS --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;' | wc -l)
    case 1 in
        $(($getmail== 0))) echo -n "$nomailicon" $getmail ;;
        $(($getmail>= 1))) echo -n "$mailicon" $getmail ;;

function tagstatus(){
    tags=( $(herbstclient tag_status) )
        for tag in "${tags[@]}" ; do
            case ${tag:0:1} in
                '#') cstart="$iconcolor" ;; # active tag
                '+') cstart="\f5"        ;;
                ':') cstart="\f5"        ;; # used tag
                '!') cstart="\f8\b5\u9"  ;; # urgent tag
                *)   cstart="\f5"        ;; # unused tag
            tagstring="${cstart} ${tag:1} $stop"
            echo -n "$tagstring"
    read hook || exit
    case "$hook" in
        tag*) tags=( $(herbstclient tag_status) ) ;;
        quit_panel*) exit ;;
while true; do echo -n "" "\\l" $(tagstatus); echo -n "\\c" $(clock); echo "\\r" $(volume) $(mpcs) ""; done | tbar -p
Could most likely use some performance tweaking, I haven't been scripting long.

[Image: 1fpz9j.png]

I don't reccomend using the mail function at present, its not really made to be in a loop, maybe make a second script, throw the function in there and run that on autostart looping once every 10 minutes or so then saving output to a file, then if [ ! $(cat <filename>) ].. you get the idea.

For the mpcs function on tracks with no tags you might want to edit the sed bit to replace the path of wherever you keep such tracks (I tried making it replace all paths but it bugs out on fast loops.)

The network function is the same, if using a slower loop it would be fine.

The irc function assumes you are using weechat and notify.pl, just pop your username in there and you are good to go.

If you notice I use tbar and not bar it is becouse I am using tbuck's fork with wrap around borders, the script works fine on either.

Now lastly, all the icons vars, I use a font called ohsnap icons for my bar, terminusmod icons should work just fine as well, other icon fonts you would want to pop open a term using the font and display them so you can replace them:
urxvt -fn "-misc-ohsnap.icons-bold-r-normal--13-120-75-75-c-60-iso8859-1"

for i in {50..255}; do printf "\\$(printf '%03o' $i)\n"; done
[Image: mg3nm7.gif]
We live as we dream, alone.

Messages In This Thread
HLWM with B.A.R - by Evolution - 02-11-2013, 10:22 PM
RE: HLWM with B.A.R - by jobss - 03-11-2013, 10:49 AM
RE: HLWM with B.A.R - by Evolution - 24-12-2013, 01:26 AM
RE: HLWM with B.A.R - by crshd - 24-12-2013, 05:30 AM
RE: HLWM with B.A.R - by Evolution - 29-12-2013, 04:06 AM