scripts

various script and utils
git clone git://z3bra.org/scripts
Log | Files | Refs

commit a874cfd7fff74d1ea76246954445839093fb0ed3
parent ce9ab30db7657ff32b273bd760c249256d10bbc4
Author: z3bra <willy@mailoo.org>
Date:   Thu Apr  3 10:43:04 +0200

Tools to generate an input well suited for a bar

Diffstat:
mkbar | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+), 0 deletions(-)
diff --git a/mkbar b/mkbar @@ -0,0 +1,83 @@ +#!/bin/sh +# +# z3bra - (c) wtfpl 2014 +# Fetch infos on your computer, and print them to stdout every second. + +clock() { + date '+%H:%M' +} + +mails() { + fcount ~/var/mail/INBOX/new +} + +battery() { + BATC=/sys/class/power_supply/BAT1/capacity + BATS=/sys/class/power_supply/BAT1/status + + # prepend percentage with a '+' if charging, '-' otherwise + test "`cat $BATS`" = "Charging" && echo -n '+' || echo -n '-' + + # append the character '%' after the number + sed 's/$/%%/' $BATC +} + +volume() { + amixer get Master | sed -n 'N;s/^.*\[\([0-9]\+%\).*$/\1%/p' +} + +cpuload() { + LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'` + echo `bc <<< $LINE`%% +} + +memused() { + read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo |awk '{print $2}'` + echo `bc <<< "scale=2; 100 - $f / $t * 100" | cut -d. -f1`%% +} + +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 + + ping -c 1 8.8.8.8 >/dev/null 2>&1 && + echo "$int up" || echo "$int down" +} + +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 + buf="%{l} " + buf="${buf} $(groups) %{r}" + buf="${buf} %{F#4c4c4c} CLK: %{F#ffffff}$(clock) " + buf="${buf} %{F#4c4c4c} NET: %{F#ffffff}$(network) " + buf="${buf} %{F#4c4c4c} CPU: %{F#ffffff}$(cpuload) " + buf="${buf} %{F#4c4c4c} RAM: %{F#ffffff}$(memused) " + buf="${buf} %{F#4c4c4c} VOL: %{F#ffffff}$(volume)  " + + echo $buf + sleep 1 # The HUD will be updated every second +done