bar.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/dash
  2. # ^c$var^ = fg color
  3. # ^b$var^ = bg color
  4. interval=0
  5. # load colors
  6. . ~/.config/chadwm/scripts/bar_themes/nord
  7. cpu() {
  8. cpu_val=$(grep -o "^[^ ]*" /proc/loadavg)
  9. printf "^c$black^ ^b$green^ CPU"
  10. printf "^c$white^ ^b$grey^ $cpu_val"
  11. }
  12. pkg_updates() {
  13. #updates=$(doas xbps-install -un | wc -l) # void
  14. updates=$(checkupdates | wc -l) # arch , needs pacman contrib
  15. # updates=$(aptitude search '~U' | wc -l) # apt (ubuntu,debian etc)
  16. if echo "$updates" | grep -q "^0$"; then
  17. printf "^c$green^ Fully Updated"
  18. else
  19. printf "^c$green^ $updates"" updates"
  20. fi
  21. }
  22. get_volume() {
  23. percent="$(amixer sget Master | grep 'Front Left:' | \
  24. awk -F '[\\]\\[]' '{print $2}' | sed 's/\%$//')"
  25. if amixer sget Master | grep -q "off"; then
  26. volume_icon="婢"
  27. elif [ "$percent" -gt 69 ]; then
  28. volume_icon="墳"
  29. elif [ "$percent" -gt 29 ]; then
  30. volume_icon="奔"
  31. else
  32. volume_icon="奄"
  33. fi
  34. printf "^c$red^ $volume_icon "
  35. printf "^c$red^ $percent"
  36. }
  37. get_battery() {
  38. get_capacity="$(battery)"
  39. printf "^c$blue^ %s" "$get_capacity"
  40. }
  41. get_brightness() {
  42. printf "^c$red^  "
  43. printf "^c$red^%s\n" $(brightness)
  44. }
  45. mem() {
  46. printf "^c$blue^^b$black^  "
  47. printf "^c$blue^ $(free -h | awk '/^Mem/ { print $3 }' | sed s/i//g)"
  48. }
  49. wlan() {
  50. # case "$(cat /sys/class/net/wl*/operstate 2>/dev/null)" in
  51. # up) printf "^c$black^ ^b$blue^ 󰤨 ^d^%s" " ^c$blue^Connected" ;;
  52. # down) printf "^c$black^ ^b$blue^ 󰤭 ^d^%s" " ^c$blue^Disconnected" ;;
  53. # esac
  54. upstate=$(ip a | grep BROADCAST,MULTICAST | awk '{print $9}' | head -n 1)
  55. case "$(cat /sys/class/net/wl*/operstate 2>/dev/null)" in
  56. down)
  57. if [ "$upstate" = "DOWN" ]; then
  58. if [ "$(rfkill | grep 'blocked' | awk '{print $4 $5}' | \
  59. sed 's/unblocked//g' | uniq | wc -l)" -eq "1" ]; then
  60. if [ "$(rfkill | grep 'blocked' | awk '{print $4 $5}' | \
  61. sed 's/unblocked//g' | grep . | wc -l)" -gt "0" ]; then
  62. printf "^c$black^ ^b$blue^ 泌^d^%s" "^c$blue^off"
  63. fi
  64. elif rfkill list wifi | grep 'Soft blocked' | awk '{print $3}' | \
  65. grep -q 'yes'; then
  66. printf "^c$black^ ^b$blue^ 󰤭 ^d^%s" "^c$blue^off"
  67. fi
  68. printf "^c$black^ ^b$blue^ ﮤ ^d^ %s" "^c$blue^$upstate"
  69. else
  70. printf "^c$black^ ^b$blue^ ﮣ ^d^ %s" "^c$blue^$upstate"
  71. fi;;
  72. up)
  73. percent=$(awk '/^\s*w/ { print int($3 * 100 / 70) }' \
  74. /proc/net/wireless | sed 's/100/99/')
  75. printf "^c$black^ ^b$blue^ 󰤨 ^d^ %s" "^c$blue^$percent"
  76. esac
  77. }
  78. clock() {
  79. printf "^c$black^ ^b$darkblue^ 󱑆 "
  80. printf "^c$black^^b$blue^ $(date '+%H:%M') "
  81. }
  82. get_date() {
  83. printf "^c$black^ ^b$darkblue^  "
  84. printf "^c$black^^b$blue^ $(date '+%d.%m.%y')"
  85. }
  86. while true; do
  87. [ $interval = 0 ] || [ $(($interval % 3600)) = 0 ] && updates=$(pkg_updates)
  88. interval=$((interval + 1))
  89. sleep 1 && xsetroot -name "$updates $(get_volume) $(get_battery) $(get_brightness) $(cpu) $(mem) $(wlan) $(get_date) $(clock)"
  90. done