configfiles/bspwm/.config/scripts/bar2.sh

168 lines
3.4 KiB
Bash
Raw Normal View History

2016-11-05 22:16:16 +01:00
#!/bin/bash
cd "$(dirname $0)"
source barhelp.sh
FG="^fg(#FFFFFF)"
BG="#1d1d1f"
LABEL="^fg(AAAAAA)"
BATTERY_GOOD="^fg(#EEEEEE)"
BATTERY_LOW="^fg(#C37561)"
FONT="Liberation Mono-8"
COLOR_SERVICE_RUNNING="^fg(#EEEEEE)"
COLOR_SERVICE_STOPPED="^fg(#666666)"
ASSET=~/.config/assets
WS_UNFOCUS="^i($ASSET/wsfree.xbm)"
WS_FOCUS="^i($ASSET/ws.xbm)"
mybar () {
W=$1
A=$2
P=$3
shift 3
bar "$W" 25 5 "$A" "$P" -fn "$FONT" -bg "$BG" -e - -ta c $@
}
clock() {
while true; do
echo "${LABEL}Time:${FG} $(date '+%a %d %b') | $(date '+%H:%M:%S')"
sleep 1;
done
}
battery() {
while true; do
level=$(acpi -b | awk -F, 'BEGIN { s=0 } { s+=$2 } END { print int(s/NR) }')
if [ "$level" -lt 20 ]; then
batlev="${BATTERY_LOW}$level%${FG}"
else
batlev="${BATTERY_GOOD}$level%${FG}"
fi
if [ -n "$(acpi -a | grep on-line)" ]; then
batcha="Charging"
else
batcha="Discharging"
fi
echo "${LABEL}Battery:${FG} $batlev, $batcha"
sleep 30
done
}
wifi() {
while true; do
info=$(nmcli -t -f state,device,connection d | awk -F: '{ if($1=="connected" && $2=="wlp3s0") { print $3; exit; } }')
if [ -z "$info" ]; then
info="-"
fi
echo "${LABEL}Wifi:${FG} $info"
sleep 2;
done
}
workspace() {
bspc subscribe report | while read line; do
NORMIFS=$IFS
IFS=:
set -- ${line#?}
while [ $# -gt 0 ]; do
case $1 in
[OFU]*)
echo -n "$WS_FOCUS"
;;
[ofu]*)
echo -n "$WS_UNFOCUS"
;;
esac
shift
done
echo
IFS=$NORMIFS
done
}
updates() {
get_pac() { checkupdates | wc -l; }
get_aur() { pacaur -Quaq | wc -l; }
get_useless() { pacman -Qtdq | wc -l; }
while true; do
internet=$(nmcli -t -f state d | grep connected)
if [ -z "$internet" ]; then
if [ -z "$pac" ]; then
pac=?
fi
if [ -z "$aur" ]; then
aur=?
fi
else
pac=$(get_pac)
aur=$(get_aur)
fi
useless=$(get_useless)
updates="$pac+$aur-$useless"
echo "${LABEL}Updates:${FG} ${updates}"
sleep 1m;
done
}
music() {
while true; do
if [ -n "$(mpc status | grep -e paused -e playing)" ]; then
while [ -n "$(mpc status | grep -e paused -e playing)" ]; do
info=$(mpc current -f '[%artist%] - [%title%]')
if [ -n "$(mpc status | grep -e paused)" ]; then
info="${info}, Paused"
fi
echo "${LABEL}Music:${FG} ${info}"
mpc idle 2>&1 1>/dev/null
done | mybar 400 T 0
fi
mpc idle 2>&1 1>/dev/null
done
}
service() {
service=$1
text=$2
systemctl is-active -q $service
if [ "$?" -eq 0 ]; then
echo -n "${COLOR_SERVICE_RUNNING}$text${FG}"
else
echo -n "${COLOR_SERVICE_STOPPED}$text${FG}"
fi
}
services() {
while true; do
service zomnet Z
echo ""
sleep 10
done
}
workspace | mybar 200 T 50 &
clock | mybar 250 B 100 &
battery | mybar 200 B 25 &
wifi | mybar 140 B 0 &
music &
updates | mybar 130 B 75 &
services | mybar 50 B 50