HLWM with B.A.R - GNU/Linux

Users browsing this thread: 3 Guest(s)
Evolution
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:

Code:
#!/usr/bin/env bash

iconcolor="\f9\b6\u9"
stop="\fr\br\ur"

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" ]
    then
        echo -n "$musicicon "
        echo -n "\f9No Track\fr" " \f7- " "\f2Playing\fr" "\f50:00/0:00"
    elif [ ! "$notags" ]
    then
        echo -n "$musicicon "
        echo -n "\f9"
        mpc current -f "%file%" | sed 's/Various Artists\/Mix\///;s/\.mp3//;s/-/\\fr\\f7-\\f2/'
    else
        echo -n "$musicicon "
        echo -n "\f9"
        mpc current -f "%artist%"
        echo -n "\fr"
        echo -n "\f7- "
        echo -n "\f2"
        mpc current -f "%title%"
    fi
}

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) ]
    then
        echo -n "$ircicon" "(IRC) Disconnected"
    else
        echo -n "$ircicon" "${im}"
    fi
}

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 ;;
    esac
}

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" ;;
    esac
}

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 ;;
    esac
}

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
            esac
            tagstring="${cstart} ${tag:1} $stop"
            echo -n "$tagstring"
        done
    echo
    read hook || exit
    case "$hook" in
        tag*) tags=( $(herbstclient tag_status) ) ;;
        quit_panel*) exit ;;
    esac
}
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.

Scrot:
[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:
Code:
urxvt -fn "-misc-ohsnap.icons-bold-r-normal--13-120-75-75-c-60-iso8859-1"

Then:
Code:
for i in {50..255}; do printf "\\$(printf '%03o' $i)\n"; done
[Image: mg3nm7.gif]
We live as we dream, alone.
jobss
Long time nixers
I'm in love with that scrot.
The world is quaking from our Linux Thoughts!
Evolution
Long time nixers
I really need to update this, and stick those icons in an array.
[Image: mg3nm7.gif]
We live as we dream, alone.
crshd
Registered
I would make a function for icons.

Code:
function icon {
   echo -n ${iconcolor} ${1} ${stop}
}

Then you could use anything as an icon without having to create a new variable/append your array.

Other than that, nice post. Scripting a BAR config isn't much different from dzen, except for the different format.
And by the way, if you're running multiple dzen instances, you're doing it wrong :P

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCA/IT d-(---)@ s+: a-- C+++(++++)$ UBL*+++ P+++>++++ L++ E W+++$ !N !o K !w !O M+>++ !V PS+++ PE !Y PGP+ !t-- !5 !X R@ tv- b+ DI D+ G e h r++ y+
------END GEEK CODE BLOCK------

Evolution
Long time nixers
(24-12-2013, 05:30 AM)crshd Wrote: I would make a function for icons.

Code:
function icon {
   echo -n ${iconcolor} ${1} ${stop}
}

Then you could use anything as an icon without having to create a new variable/append your array.

Other than that, nice post. Scripting a BAR config isn't much different from dzen, except for the different format.
And by the way, if you're running multiple dzen instances, you're doing it wrong :P

Well I do have to say that I never put much effort into actually experimenting with dzen, maybe its just because I had a bad experience with it in the beginning with positioning.
[Image: mg3nm7.gif]
We live as we dream, alone.