lemonbar-bar.sh (4884B)
1 #!/bin/sh 2 3 echo "$$" > ~/.cache/bar_pid 4 5 . "$XDG_CONFIG_HOME/regexghost/current-theme.sh" 6 7 COLOUR_RESET="%{F-}" 8 sunset_colour="%{F#${RED}}" 9 sunrise_colour="%{F#${YELLOW}}" 10 network_down_colour="%{F#${MAGENTA}}" 11 cpu_colour="%{F#${BLUE}}" 12 cpu_temp_colour="%{F#${RED}}" 13 memory_colour="%{F#${YELLOW}}" 14 uptime_colour="%{F#${GREEN}}" 15 muted_colour="%{F#${RED}}" 16 volume_colour="%{F#${GREEN}}" 17 music_stopped_colour="%{F#${RED}}" 18 music_playing_colour="%{F#${GREEN}}" 19 music_paused_colour="%{F#${YELLOW}}" 20 wifi_up_colour="%{F#${GREEN}}" 21 wifi_down_colour="%{F#${RED}}" 22 stream_live_colour="%{F#${GREEN}}" 23 stream_not_live_colour="%{F#${YELLOW}}" 24 stream_error_colour="%{F#${RED}}" 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} ${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 cpu_temp="${cpu_temp_colour} "$(vcgencmd measure_temp | cut -d "=" -f 2 | cut -d "." -f 1)°C"${COLOUR_RESET}" 62 } 63 64 update_uptime () { 65 uptime="${uptime_colour} "$(~/.local/share/regexghost/panel/uptime)"${COLOUR_RESET}" 66 } 67 68 update_sunrise () { 69 sunrise="${sunrise_colour} "$(~/.local/share/regexghost/panel/sunrise.sh --sunrise --blank)"${COLOUR_RESET}" 70 } 71 72 update_sunset () { 73 sunset="${sunset_colour} "$(~/.local/share/regexghost/panel/sunrise.sh --sunset --blank)"${COLOUR_RESET}" 74 } 75 76 update_weather () { 77 weather_days="$(~/.local/share/regexghost/panel/metoffice.sh)" 78 weather_today="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '1q;d')")" 79 weather_tomorrow="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '2q;d')")" 80 weather_2_days="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '3q;d')")" 81 weather="0${weather_today} 1${weather_tomorrow} 2${weather_2_days}" 82 } 83 84 # This is done by index so I can change the streams checked by just altering the order in the config file 85 stream_live () { 86 streamer_name="$(sed -n "${1}p" "$XDG_CONFIG_HOME/regexghost/streams.csv" | cut -d "," -f 1)" 87 first_char="$(echo "$streamer_name" | cut -c 1-1)" 88 live="$(stream-check -yn "$streamer_name")" 89 if [ "$live" = "y" ]; then 90 echo "${first_char} ${stream_live_colour} ${COLOUR_RESET}" 91 elif [ "$live" = "w" ]; then 92 echo "${first_char} ${stream_not_live_colour} ${COLOUR_RESET}" 93 elif [ "$live" = "n" ]; then 94 echo "${first_char} ${stream_not_live_colour} ${COLOUR_RESET}" 95 else 96 echo "${first_char} ${stream_error_colour} ${COLOUR_RESET}" 97 fi 98 } 99 100 update_streams () { 101 stream="$(stream_live 1) $(stream_live 2) $(stream_live 3)" 102 } 103 104 update_music () { 105 state="$(mocp -M "$XDG_CONFIG_HOME/moc" -i)" 106 song="$(echo "$state" | grep -e "SongTitle" -e "Artist" | tac | tr "\n" "-" | sed 's/-Artist: / - /g' | sed 's/^SongTitle: //g; s/"//g' | string-trunc 16 ".." | sed 's/ $//g')" 107 pause="$(echo "$state" | grep -e "State" | cut -d " " -f 2)" 108 if [ "$song" = "" ]; then 109 music="${music_stopped_colour} N/A${COLOUR_RESET}" 110 elif [ "$pause" = "PLAY" ]; then 111 music="${music_playing_colour} ${song}${COLOUR_RESET}" 112 else 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 display () { 146 echo "%{r} ${music} | ${stream}| ${sunset} | ${sunrise} | ${weather}| ${vol} | ${network_down} | ${wifi} | ${cpu} | ${uptime} | ${cpu_temp} | ${memory} | ${current_time} " 147 } 148 149 update_vol 150 update_wifi 151 update_time 152 update_sunrise 153 update_sunset 154 update_weather 155 update_streams 156 update_music 157 158 i=1 159 160 trap "update_vol;display" "RTMIN" 161 trap "update_music;display" "RTMIN+1" 162 163 while true; do 164 sleep 2 & wait && { 165 update_network_down 166 update_cpu 167 update_mem 168 update_uptime 169 update_cpu_temp 170 update_vol 171 [ $((i%3)) -eq 0 ] && update_time 172 [ $((i%3)) -eq 0 ] && update_wifi 173 [ $((i%3)) -eq 0 ] && update_music 174 [ $((i % 180)) -eq 0 ] && update_sunset 175 [ $((i % 300)) -eq 0 ] && update_sunrise 176 [ $((i % 600)) -eq 0 ] && update_streams 177 [ $((i % 360)) -eq 0 ] && update_weather 178 i=$((i+1)) 179 [ $i -gt 900 ] && i=0 180 display 181 } 182 done