Skip to content

Instantly share code, notes, and snippets.

@kiedtl
Created March 2, 2020 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiedtl/8c22d4bd7f5c463af7497cbe1de95775 to your computer and use it in GitHub Desktop.
Save kiedtl/8c22d4bd7f5c463af7497cbe1de95775 to your computer and use it in GitHub Desktop.
z-brah's bar
#!/bin/sh
bg=#00ffffff
fg=#ff666b7d
fn='IBM Plex Mono:pixelsize=14:antialias=true:autohint=true'
clock() {
LANG=fr_FR.UTF-8 printf '%s %%{R} %s %%{R}' "$(date '+%a %d')" "$(date +%H:%M)"
}
wifi() {
if=${1:-wlp2s0}
rfkill="$(LC_ALL=C rfkill -r | grep wlan | cut -d ' ' -f 4)"
[ "$rfkill" = "blocked" ] && return
ssid=$(iwgetid -r $if)
printf 'ssid %%{R} %s %%{R}' "${ssid:--}"
}
# my ethernet and wifi cards are bonded together, so I check the active slave to
# know where I'm connected.
# Most people use a network manager instead to switch between networks (which sucks
# if ask me, but hey, to each their own!).
bonding() {
if=$(grep 'Currently Active Slave:' /proc/net/bonding/${1:-bond0} | cut -d ' ' -f4)
case $if in
wlp2s0) wifi $if ;;
enp0s31f6) printf 'wired %%{R} %s %%{R}' $if ;;
*) printf '%%{R} offline %%{R}' ;;
esac
}
# click on volume to toggle it
# mouse scroll on volume to increase/decrease
# require scripts named "speakers" and "microphone" to be in $PATH to work
sound() {
printf 'vol %%{R} '
printf '%%{A:speakers toggle:}'
printf '%%{A4:speakers 5%%+:}'
printf '%%{A5:speakers 5%%-:}'
printf '%s%%{A}%%{A}%%{A}' "$(speakers)"
printf ' %%{R} mic %%{R} '
printf '%%{A:microphone toggle:}'
printf '%%{A4:microphone 5%%+:}'
printf '%%{A5:microphone 5%%-:}'
printf '%s%%{A}%%{A}%%{A}' "$(microphone)"
printf ' %%{R}'
}
battery() {
lvl="$(cat /sys/class/power_supply/$1/capacity)"
ac="$(cat /sys/class/power_supply/$1/status)"
case $ac in
Charging) ac='+' ;;
*) ac='' ;;
esac
printf '%d%%%c\n' "$lvl" "$ac"
}
while sleep 1; do
printf '%%{c} %s %s %s %s %s %s\n' \
"$(bonding bond0)" \
"$(sound)" \
"$(clock)" \
"$(battery BAT0)"
done| lemonbar -db -B "$bg" -F "$fg" -f "$fn" -g 1920x32+0+0 | sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment