Skip to content

Commit

Permalink
dwm-statusbar: make code a little neater
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Wong committed Jan 25, 2013
1 parent a889240 commit 2009cfb
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions dwm-statusbar
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@
#
# ~/bin/dwm-statusbar
#
# Status bar for dwm. Idea from:
# Status bar for dwm. Expanded from:
# https://bitbucket.org/jasonwryan/eeepc/src/73dadb289dead8ef17ef29a9315ba8f1706927cb/Scripts/dwm-status

print_song_info() {
song_info="$(ncmpcpp --now-playing '\x09{{{{%t - }%a}}|{%f}}' | head -c 75)"
[[ ! $song_info ]] && song_info="Off"
if [[ ! $song_info ]]; then
song_info="Off"
fi
echo -ne "\x04\uE01D\x0F\uE00E ${song_info}"
}

print_torrent_status() {
torrent_status="$(transmission-remote -l | awk '/\ \ Up\ &\ Down\ \ / &&\
! /\ \ Unknown\ \ / {print "\\x07"$5$6}')"
[[ ! $torrent_status ]] &&
torrent_status="$(transmission-remote -l | awk '/\ \ Downloading\ \ / &&\
! /\ \ Unknown\ \ / {print "\\x07"$5$6}')"
[[ ! $torrent_status ]] && torrent_status="Idle"
echo -ne "\x04\uE01C\uE01D\x0D\uE017 ${torrent_status}" | head -n 1
torrent_status="$(transmission-remote -l | awk -F " +" '$5 ~ /^[0-9]/ {print $5}')"
if [[ ! $torrent_status ]]; then
torrent_status="Idle"
else
torrent_status="\x07${torrent_status}"
fi
echo -ne "\x04\uE01C\uE01D\x0D\uE017 ${torrent_status}"
}

print_email_unread() {
gmail_unread="$(find $HOME/.mutt/maildir/gmail/inbox/new -type f | wc -l)"
mq_unread="$(find $HOME/.mutt/maildir/mq/inbox/new -type f | wc -l)"
wongdev_unread="$(find $HOME/.mutt/maildir/wongdev/inbox/new -type f | wc -l)"
[[ $gmail_unread -ne 0 ]] && gmail_unread="\x07${gmail_unread}\x0D"
[[ $mq_unread -ne 0 ]] && mq_unread="\x07${mq_unread}\x0D"
[[ $wongdev_unread -ne 0 ]] && wongdev_unread="\x07${wongdev_unread}"
echo -ne "\x04\uE01C\uE01D\x0D\uE014 ${gmail_unread} ${mq_unread} ${wongdev_unread}"
echo -ne "\x04\uE01C\uE01D\x0D\uE014"
for maildir in $(find $HOME/.mutt/maildir/*/inbox/new -type d); do
unread_count="$(ls "${maildir}" | wc -l)"
if [[ $unread_count -ne 0 ]]; then
echo -ne " \x07${unread_count}"
else
echo -ne " \x0D0"
fi
done
}

print_last_msg() {
Expand All @@ -37,13 +41,15 @@ print_last_msg() {
}

print_mem_used() {
mem_used="$(free -m | awk '/buffers\/cache/ {print $3}')"
mem_used="$(free -m | awk 'NR==3 {print $3}')"
echo -ne " \x0E\uE010 \x08${mem_used}M"
}

print_volume() {
volume="$(amixer get PCM | tail -n1 | sed -r 's/.*\[(.*)%\].*/\1/')"
[[ $volume -ne 0 ]] && volume="\x0A${volume}"
if [[ $volume -ne 0 ]]; then
volume="\x0A${volume}"
fi
echo -ne "\x04\uE01C\uE01D\x10\uE015 ${volume}%"
}

Expand Down

0 comments on commit 2009cfb

Please sign in to comment.