bar.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. div="%{F#0092ff}<>%{F-}%{B-}"
  3. # Global var, last epoch time we checked email
  4. # Update this when we call email() so that we can
  5. # call email() every second, but only call himalaya
  6. # once every minute
  7. LAST_EMAIL_CHECK_EPOCH=$(date +%s)
  8. EMAIL_STATE="Email: No new emails"
  9. email() {
  10. EPOCH_NOW=$(date +%s)
  11. DIFF=$((EPOCH_NOW - $LAST_EMAIL_CHECK_EPOCH))
  12. if [ $DIFF -gt 60 ]; then
  13. NEW_EMAILS=$(himalaya list -s 1 | grep ✷ | wc -l)
  14. if [ $NEW_EMAILS -gt 0 ]; then
  15. EMAIL_STATE="Email: ** New Emails **"
  16. LAST_EMAIL_CHECK_EPOCH=$(date +%s)
  17. else
  18. EMAIL_STATE="Email: No new emails"
  19. fi
  20. fi
  21. echo -n "$EMAIL_STATE"
  22. echo -n " Last Checked: $LAST_EMAIL_CHECK_EPOCH "
  23. }
  24. Clock() {
  25. DATETIME=$(date "+%a %b %d, %T")
  26. echo -n "$DATETIME"
  27. }
  28. cpuTemp() {
  29. CPUTEMP=$(sensors | grep CPU | awk '{print $2}')
  30. echo -n "CPU Temp: $CPUTEMP"
  31. }
  32. batteryInfo() {
  33. capacityRemaining=$(cat /sys/class/power_supply/BAT0/capacity)
  34. batteryStatus=$(cat /sys/class/power_supply/BAT0/status)
  35. if [[ $capacityRemaining -lt 25 ]]; then
  36. capacityRemaining="%{F#ff5b00}$capacityRemaining %{F-}%{B-}"
  37. fi
  38. if [[ "$batteryStatus" == "Charging" ]]; then
  39. batteryStatus="%{F#ff9966}$batteryStatus%{F-}%{B-}"
  40. fi
  41. capacityRemaining=$capacityRemaining%
  42. echo -n "Battery: $capacityRemaining $batteryStatus"
  43. }
  44. wifiInfo() {
  45. connectionName=$(wpa_cli status | egrep "^ssid" | sed s/ssid=//g)
  46. ipAddr=$(wpa_cli status | egrep "^ip" | sed s/ip_address=//g)
  47. echo -n "Wifi: $connectionName $div IP: $ipAddr"
  48. }
  49. ethPort() {
  50. linkDetected=$(cat /sys/class/net/enp0s31f6/carrier)
  51. if [[ $linkDetected -eq 0 ]]; then
  52. connected="eth0: down"
  53. elif [[ $linkDetected -eq 1 ]]; then
  54. connected="eth0: up"
  55. fi
  56. echo -n "$connected"
  57. }
  58. diskFree() {
  59. freeNVME=$(df -h /dev/mapper/decryptedRoot-root | awk '{print $4}' | tail -n1)
  60. echo -n "NVMe Free: $freeNVME"
  61. }
  62. loadAvg() {
  63. la=$(uptime | grep -o :\ [0-9].* | sed s/://g | awk '{print $1}' | sed s/,//g)
  64. if (( $(echo "$la > 8" |bc -l) )); then
  65. la="%{F#ff5b00}$la%{F-}%{B-}"
  66. else
  67. la="%{F#ff9966}$la%{F-}%{B-}"
  68. fi
  69. echo -n "Load: $la"
  70. }
  71. soundState() {
  72. muted=$(pactl list sinks | grep Mute: | awk '{print $2}')
  73. if [[ "$muted" == yes ]]; then
  74. state="Volume: 0%"
  75. else
  76. level=$(pactl list sinks | grep Volume: | awk '{print $5}' | head -n1)
  77. state="Volume: $level"
  78. fi
  79. echo -n $state
  80. }
  81. while true; do
  82. sleep 1
  83. echo "%{l} $(Clock) $div $(cpuTemp) $div $(loadAvg) $div $(wifiInfo) $div $(ethPort) $div $(diskFree) $div $(soundState) $div $(batteryInfo) $div $(email)"
  84. sleep 0.5
  85. done