Last active
October 3, 2023 11:46
-
-
Save 0x1d107/c876427983b583f98f5c2e3814349524 to your computer and use it in GitHub Desktop.
lemonbar script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| export MPD_HOST=~/.mpd/socket | |
| function clock { | |
| date +"%H:%M" | |
| } | |
| function desktop { | |
| printf "[%4s]" "$(bspc query -D -d focused --names)" | |
| } | |
| function layout { | |
| xkb-switch -p | |
| } | |
| function battery { | |
| BATTERY=/sys/class/power_supply/BAT0 | |
| NOW=$(cat $BATTERY/charge_now) | |
| FULL=$(cat $BATTERY/charge_full) | |
| printf "%02d%%" "$((NOW*100/FULL))" | |
| } | |
| function now_playing { | |
| printf "%.62s" "$(mpc current)" | |
| } | |
| function clock_update { | |
| while true | |
| do | |
| sleep $(( 60 - $(date +%s) % 60 )) | |
| echo clock_update | |
| done | |
| } | |
| function bspwm_update { | |
| bspc subscribe desktop | |
| } | |
| function layout_update { | |
| xkb-switch -W | |
| } | |
| function now_playing_update { | |
| while true; | |
| do | |
| mpc idle player | |
| echo | |
| done | |
| } | |
| function bar { | |
| echo "%{l}$(desktop) $(now_playing) %{c}$(clock) %{r}$(layout) $(battery)" | |
| } | |
| function bar_update { | |
| bar | |
| while read EVENT | |
| do | |
| bar | |
| done < $UPDATE | |
| } | |
| UPDATE=/tmp/bar_update | |
| PID_FILE=/tmp/bar_pids | |
| trap "xargs kill < $PID_FILE;rm $PID_FILE" EXIT | |
| if [ -e $PID_FILE ] | |
| then | |
| echo lemonade.sh exists! >&2 | |
| exit 1 | |
| fi | |
| [ -e $UPDATE ] || mkfifo $UPDATE | |
| clock_update > $UPDATE & | |
| echo $! > $PID_FILE | |
| bspwm_update > $UPDATE & | |
| echo $! >> $PID_FILE | |
| layout_update > $UPDATE & | |
| echo $! >> $PID_FILE | |
| now_playing_update > $UPDATE & | |
| echo $! >> $PID_FILE | |
| bar_update| lemonbar -f monospace:size=9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment