dwm-bar.sh (4686B)
1 #!/bin/sh 2 3 echo "$$" > ~/.cache/bar_pid 4 5 . "$XDG_CONFIG_HOME/regexghost/current-theme.sh" 6 7 COLOUR_RESET="\x01" 8 sunset_colour="\x02" 9 sunrise_colour="\x04" 10 network_down_colour="\x06" 11 cpu_colour="\x05" 12 cpu_temp_colour="\x02" 13 memory_colour="\x04" 14 uptime_colour="\x03" 15 muted_colour="\x02" 16 volume_colour="\x03" 17 music_stopped_colour="\x02" 18 music_playing_colour="\x03" 19 music_paused_colour="\x04" 20 wifi_up_colour="\x03" 21 wifi_down_colour="\x02" 22 stream_live_colour="\x02" 23 stream_not_live_colour="\x03" 24 stream_error_colour="\x02" 25 26 update_time () { 27 current_time="$(date +"%a %d %b - %H:%M")" 28 } 29 30 update_cpu () { 31 cpu="${cpu_colour}$(~/.local/share/regexghost/panel/cpu)%${COLOUR_RESET}" 32 } 33 34 update_network_down () { 35 network_down="${network_down_colour}"$(~/.local/share/regexghost/panel/network_down)"${COLOUR_RESET}" 36 } 37 38 update_vol () { 39 if [ $(cat ~/.cache/muted) = "yes" ]; then 40 vol="${muted_colour}Muted${COLOUR_RESET}" 41 else 42 vol="${volume_colour}$(cat ~/.cache/volume)%%${COLOUR_RESET}" 43 fi 44 } 45 46 update_wifi () { 47 con="$(nmcli -t -f NAME c show --active | grep -v "^lo$" | string-trunc 6 ".." | sed 's/ $//g')" 48 if [ "$con" = "" ]; then 49 wifi="${wifi_down_colour}N/A${COLOUR_RESET}" 50 51 else 52 wifi="${wifi_up_colour}${con}${COLOUR_RESET}" 53 fi 54 } 55 56 update_mem () { 57 memory="${memory_colour}"$(free -m | awk '/Mem:/ {print $3}')MiB"${COLOUR_RESET}" 58 } 59 60 update_cpu_temp () { 61 temp=$(($(cat /sys/class/thermal/thermal_zone2/temp)/1000)) 62 cpu_temp="${cpu_temp_colour}""${temp}°C""${COLOUR_RESET}" 63 } 64 65 update_uptime () { 66 uptime="${uptime_colour}"$(~/.local/share/regexghost/panel/uptime)"${COLOUR_RESET}" 67 } 68 69 update_sunrise () { 70 sunrise="${sunrise_colour}"$(~/.local/share/regexghost/panel/sunrise.sh --sunrise --blank)"${COLOUR_RESET}" 71 } 72 73 update_sunset () { 74 sunset="${sunset_colour}"$(~/.local/share/regexghost/panel/sunrise.sh --sunset --blank)"${COLOUR_RESET}" 75 } 76 77 #update_weather () { 78 # weather_days="$(~/.local/share/regexghost/panel/metoffice.sh)" 79 # weather_today="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '1q;d')")" 80 # weather_tomorrow="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '2q;d')")" 81 # weather_2_days="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '3q;d')")" 82 # weather="0${weather_today} 1${weather_tomorrow} 2${weather_2_days}" 83 #} 84 85 # This is done by index so I can change the streams checked by just altering the order in the config file 86 stream_live () { 87 streamer_name="$(sed -n "${1}p" "$XDG_CONFIG_HOME/regexghost/streams.csv" | cut -d "," -f 1)" 88 first_char="$(echo "$streamer_name" | cut -c 1-1)" 89 live="$(stream-check -yn "$streamer_name")" 90 if [ "$live" = "y" ]; then 91 echo "${first_char} ${stream_live_colour}L ${COLOUR_RESET}" 92 elif [ "$live" = "w" ]; then 93 echo "${first_char} ${stream_not_live_colour}U ${COLOUR_RESET}" 94 elif [ "$live" = "n" ]; then 95 echo "${first_char} ${stream_not_live_colour}O ${COLOUR_RESET}" 96 else 97 echo "${first_char} ${stream_error_colour}E ${COLOUR_RESET}" 98 fi 99 } 100 101 update_streams () { 102 stream="$(stream_live 1) $(stream_live 2) $(stream_live 3)" 103 } 104 105 update_music () { 106 state="$(mpc status | grep "^\[")" 107 song="$(mpc current -f '%title% - %artist%' | string-trunc 16 ".." | sed 's/ $//g')" 108 if [ "$state" = "" ]; then 109 music="${music_stopped_colour}N/A${COLOUR_RESET}" 110 elif echo "$state" | grep -q "playing"; then 111 music="${music_playing_colour}${song}${COLOUR_RESET}" 112 elif echo "$state" | grep -q "paused"; then 113 music="${music_paused_colour}${song}${COLOUR_RESET}" 114 fi 115 } 116 117 # 118 # 119 # 120 # 121 # 122 # 123 # 124 # 125 # 126 # 127 # 128 # 129 # 130 # 131 # 132 # 133 # 134 # 135 # 136 # 137 # 138 # 139 # 140 # 141 # 142 # 143 # 144 # 145 146 display () { 147 printf " ${music} | ${stream}| ${sunset} | ${sunrise} | ${vol} | ${network_down} | ${wifi} | ${cpu} | ${uptime} | ${cpu_temp} | ${memory} | ${current_time} " 148 } 149 150 display 151 152 update_vol 153 update_wifi 154 update_time 155 update_sunrise 156 update_sunset 157 #update_weather 158 update_streams 159 update_music 160 161 i=1 162 163 trap "update_vol;display" "RTMIN" 164 trap "update_music;display" "RTMIN+1" 165 166 mpd () { 167 mpc idleloop player | while read -r _; do 168 kill -35 $(cat ~/.cache/bar_pid) 169 done & 170 } 171 172 mpd & 173 174 while true; do 175 sleep 2 & wait && { 176 update_network_down 177 update_cpu 178 update_mem 179 update_uptime 180 update_cpu_temp 181 update_vol 182 [ $((i%3)) -eq 0 ] && update_time 183 [ $((i%3)) -eq 0 ] && update_wifi 184 [ $((i%3)) -eq 0 ] && update_music 185 [ $((i % 180)) -eq 0 ] && update_sunset 186 [ $((i % 300)) -eq 0 ] && update_sunrise 187 [ $((i % 600)) -eq 0 ] && update_streams 188 # [ $((i % 360)) -eq 0 ] && update_weather 189 i=$((i+1)) 190 [ $i -gt 900 ] && i=0 191 display 192 } 193 done