Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bar.sh #201

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions scripts/bar.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/dash
#!/bin/bash

# ^c$var^ = fg color
# ^b$var^ = bg color
Expand All @@ -8,33 +8,24 @@ interval=0
# load colors
. ~/.config/chadwm/scripts/bar_themes/onedark

cpu() {
cpu_val=$(grep -o "^[^ ]*" /proc/loadavg)

printf "^c$black^ ^b$green^ CPU"
printf "^c$white^ ^b$grey^ $cpu_val"
}

# Update checking function (Arch Linux)
pkg_updates() {
#updates=$({ timeout 20 doas xbps-install -un 2>/dev/null || true; } | wc -l) # void
updates=$({ timeout 20 checkupdates 2>/dev/null || true; } | wc -l) # arch
# updates=$({ timeout 20 aptitude search '~U' 2>/dev/null || true; } | wc -l) # apt (ubuntu, debian etc)

if [ -z "$updates" ]; then
updates=$(checkupdates 2>/dev/null | wc -l)
if [[ -z "$updates" ]]; then
printf " ^c$green^  Fully Updated"
else
printf " ^c$green^  $updates"" updates"
printf " ^c$green^  $updates updates"
fi
}

battery() {
get_capacity="$(cat /sys/class/power_supply/BAT1/capacity)"
printf "^c$blue^  $get_capacity"
get_capacity="$(cat /sys/class/power_supply/BAT0/capacity)"
printf "^c$blue^  $get_capacity%%"
}

brightness() {
printf "^c$red^  "
printf "^c$red^%.0f\n" $(cat /sys/class/backlight/*/brightness)
printf "^c$red^%.0f\n" "$(cat /sys/class/backlight/*/brightness)"
}

mem() {
Expand All @@ -43,21 +34,20 @@ mem() {
}

wlan() {
case "$(cat /sys/class/net/wl*/operstate 2>/dev/null)" in
up) printf "^c$black^ ^b$blue^ 󰤨 ^d^%s" " ^c$blue^Connected" ;;
down) printf "^c$black^ ^b$blue^ 󰤭 ^d^%s" " ^c$blue^Disconnected" ;;
esac
case "$(cat /sys/class/net/wl*/operstate 2>/dev/null)" in
up) printf "^c$black^ ^b$blue^ 󰤨 ^d^%s" " ^c$blue^Connected" ;;
down) printf "^c$black^ ^b$blue^ 󰤭 ^d^%s" " ^c$blue^Disconnected" ;;
esac
}

clock() {
printf "^c$black^ ^b$darkblue^ 󱑆 "
printf "^c$black^^b$blue^ $(date '+%H:%M') "
printf "^c$black^ ^b$darkblue^ 󱑆 "
printf "^c$black^^b$blue^ $(date '+%H:%M') "
}

# Main loop
while true; do

[ $interval = 0 ] || [ $(($interval % 3600)) = 0 ] && updates=$(pkg_updates)
interval=$((interval + 1))

sleep 1 && xsetroot -name "$updates $(battery) $(brightness) $(cpu) $(mem) $(wlan) $(clock)"
updates=$(pkg_updates) # Update every loop now. Less resource intensive than checking every second.
xsetroot -name "$updates $(battery) $(brightness) $(volume) $(mem) $(wlan) $(clock)"
sleep 3600
done