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

169 lines
3.5 KiB
Bash
Executable file

#!/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)"
BATTERY_CHARGING="^fg(#66a84a)"
BATTERY_DISCHARGING="^fg(#C37561)"
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}T:${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="${BATTERY_CHARGING}+${FG}"
else
batcha="${BATTERY_DISCHARGING}-${FG}"
fi
echo "${LABEL}B:${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}W:${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}U:${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}M:${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 180 T 50 &
clock | mybar 230 B 100 &
battery | mybar 100 B 29 &
wifi | mybar 200 B 0 &
music &
updates | mybar 100 B 71 &
services | mybar 50 B 50