#!/usr/bin/env bash ## ┬ ┌─┐┌┬┐┌─┐┌┐┌┌┐ ┌─┐┬─┐ ## │ ├┤ ││││ ││││├┴┐├─┤├┬┘ ## ┴─┘└─┘┴ ┴└─┘┘└┘└─┘┴ ┴┴└─ clock() { date '+%d/%m %H:%M' } battery() { BATC=/sys/class/power_supply/BAT1/capacity BATS=/sys/class/power_supply/BAT1/status test "`cat $BATS`" = "Charging" && echo -n '+' || echo -n '-' sed -n p $BATC } volume() { amixer get Master | sed -n 's/^.*\[\([0-9]\+\)%.*$/\1/p'| uniq } cpuload() { LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'` bc <<< $LINE } memused() { free -m | awk 'NR==2{printf "%.2f", $3*100/$2}' } network() { read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'` if iwconfig $int1 >/dev/null 2>&1; then wifi=$int1 eth0=$int2 else wifi=$int2 eth0=$int1 fi ip link show $eth0 | grep 'state UP' >/dev/null && int=$eth0 ||int=$wifi #int=eth0 ping -c 1 8.8.8.8 >/dev/null 2>&1 && echo "$int +" || echo "$int -" } groups() { cur=`xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}'` tot=`xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}'` for w in `seq 0 $((cur - 1))`; do line="${line}="; done line="${line}|" for w in `seq $((cur + 2)) $tot`; do line="${line}="; done echo $line } nowplaying() { cur=`mpc current` ## this line allow to choose whether the output will scroll or not test "$1" = "scroll" && PARSER='skroll -n20 -d0.5 -r' || PARSER='cat' test -n "$cur" && $PARSER <<< $cur || echo "-- stopped --" } ## this loop will fill a buffer with our infos, and output it to stdout. while :; do echo "%{l} $(nowplaying)\ %{r} $(cpuload)/$(memused) $(network) $(volume) $(clock)" sleep 1 ## the bar will be updated every second done