diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-11-27 23:51:40 -0500 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-11-27 23:51:40 -0500 |
| commit | 153e05578f227a6d88c3a56db7b3de1f32491ee5 (patch) | |
| tree | e261417e199f448d4284161bc08e284585949f81 | |
| parent | Turn off audio bell (diff) | |
| download | dotfiles-153e05578f227a6d88c3a56db7b3de1f32491ee5.zip | |
Update bar
| -rwxr-xr-x | lemonbar-xft/.config/lemonbar-xft/bar.sh | 109 |
1 files changed, 64 insertions, 45 deletions
diff --git a/lemonbar-xft/.config/lemonbar-xft/bar.sh b/lemonbar-xft/.config/lemonbar-xft/bar.sh index 7b486a3..4cfcb9b 100755 --- a/lemonbar-xft/.config/lemonbar-xft/bar.sh +++ b/lemonbar-xft/.config/lemonbar-xft/bar.sh @@ -4,39 +4,37 @@ RED="%{F#cd0000}" YELLOW="%{F#cdcd00}" RESET="%{F-}" -net() { - ifconfig egress 2>/dev/null | awk '/inet / {print $2}' +main() { + while true; do + update_bar + sleep 5 + done } -wifi() { - wifi_info=$(ifconfig iwm0 2>/dev/null | grep "ieee80211:") - if [ -n "$wifi_info" ]; then - ssid=$(echo "$wifi_info" | sed -n 's/.*join \(.*\) chan.*/\1/p' | tr -d '"') - signal=$(ifconfig iwm0 | awk '/ieee80211:/ {for(i=1;i<=NF;i++) if($i ~ /%/) print $i}' | head -1) - printf "%s %s %s" "$ssid" "$signal" "$(net)" - else - net - fi +update_bar() { + printf "%%{l} %s | %s | %s | %s | %s %%{r} %s | %s | %s \n" \ + "$(battery)" \ + "$(temp)" \ + "$(cpu)" \ + "$(memory)" \ + "$(brightness)" \ + "$(volume)" \ + "$(wifi)" \ + "$(datetime)" } battery() { - apm_output=$(apm -alb) - ac_state=$(echo "$apm_output" | head -1) - percent=$(echo "$apm_output" | sed -n '2p') - charging=$(echo "$apm_output" | sed -n '4p') + apm_output=$(apm -al) + percent=$(echo "$apm_output" | sed -n '1p') + batt_state=$(echo "$apm_output" | sed -n '2p') minutes=$(apm -m) - if [ "$ac_state" = "4" ]; then - echo "AC" - return - fi - filled=$((percent / 10)) bar="" i=0 while [ $i -lt 10 ]; do if [ $i -lt $filled ]; then - if [ "$charging" = "1" ]; then + if [ "$batt_state" = "1" ]; then bar="${bar}+" else bar="${bar}#" @@ -47,26 +45,15 @@ battery() { i=$((i + 1)) done - if [ "$percent" -lt 30 ] && [ "$charging" != "1" ]; then + if [ "$percent" -lt 30 ] && [ "$batt_state" != "1" ]; then bar="${RED}${bar}${RESET}" - elif [ "$percent" -lt 50 ] && [ "$charging" != "1" ]; then + elif [ "$percent" -lt 50 ] && [ "$batt_state" != "1" ]; then bar="${YELLOW}${bar}${RESET}" fi printf "%s%% %s (%s min)" "$percent" "$bar" "$minutes" } -cpu() { - apm -Pv | awk '{gsub(/\(|\)/, ""); print $5, $6, $4}' -} - -memory() { - top -n | awk '/^Memory:/ { - split($3, r, "/"); - printf "Used:%s Free:%s Cached:%s", r[2], $6, $8 - }' -} - temp() { avg=$(sysctl hw.sensors | awk -F'=' '/temp/ { gsub(/degC.*/, "", $2); @@ -83,18 +70,50 @@ temp() { fi } +cpu() { + apm -Pv | awk '{gsub(/\(|\)/, ""); print $5, $6, $4}' +} + +memory() { + top -n | awk '/^Memory:/ { + split($3, r, "/"); + printf "Used:%s Free:%s", r[2], $6 + }' +} + +net() { + ifconfig egress 2>/dev/null | awk '/inet / {print $2}' +} + +brightness() { + bright=$(xbacklight -get | cut -d. -f1) + printf "Bri: %d%%" "$bright" +} + +volume() { + vol=$(sndioctl -n output.level) + percent=$(printf "%.0f" "$(echo "$vol" | awk '{print $1 * 100}')") + + if sndioctl output.mute | grep -q "=1"; then + printf "Vol: MUTE" + else + printf "Vol: %d%%" "$percent" + fi +} + +wifi() { + wifi_info=$(ifconfig iwm0 2>/dev/null | grep "ieee80211:") + if [ -n "$wifi_info" ]; then + ssid=$(echo "$wifi_info" | sed -n 's/.*join \(.*\) chan.*/\1/p' | tr -d '"') + signal=$(ifconfig iwm0 | awk '/ieee80211:/ {for(i=1;i<=NF;i++) if($i ~ /%/) print $i}' | head -1) + printf "%s %s %s" "$ssid" "$signal" "$(net)" + else + net + fi +} + datetime() { date '+%Y-%m-%d %H:%M' } -while true; do - printf "%%{l} %s | %s | %s | %s %%{r} %s | %s \n" \ - "$(battery)" \ - "$(temp)" \ - "$(cpu)" \ - "$(memory)" \ - "$(wifi)" \ - "$(datetime)" - - sleep 5 -done +main |