dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

lemonbar-bar.sh (5140B)


      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 trap "echo not loaded yet" "RTMIN"
     27 trap "echo not loaded yet" "RTMIN+1"
     28 
     29 update_time () {
     30 	current_time="$(date +"%a %d %b - %H:%M")"
     31 }
     32 
     33 update_cpu () {
     34 	cpu="${cpu_colour} $(~/.local/share/regexghost/panel/cpu)%${COLOUR_RESET}"
     35 }
     36 
     37 update_network_down () {
     38 	network_down="${network_down_colour} "$(~/.local/share/regexghost/panel/network_down)"${COLOUR_RESET}"
     39 }
     40 
     41 update_vol () {
     42 	if [ "$(cat ~/.cache/panel_volume/sink)" = "bluez" ]; then
     43 		icon=""
     44 	else
     45 		icon=""
     46 	fi
     47 	if [ "$(cat ~/.cache/panel_volume/muted)" = "yes" ]; then
     48 		vol="${muted_colour}${COLOUR_RESET}"
     49 	else
     50 		vol="${volume_colour}${icon} $(cat ~/.cache/panel_volume/volume)%%${COLOUR_RESET}"
     51 	fi
     52 }
     53 
     54 update_wifi () {
     55 	con="$(nmcli -t -f NAME c show --active | grep -v "^lo$" | head -n 1 | string-trunc 6 ".." | sed 's/ $//g')"
     56 	if [ "$con" = "" ]; then
     57 		wifi="${wifi_down_colour} N/A${COLOUR_RESET}"
     58 
     59 	else
     60 		wifi="${wifi_up_colour} ${con}${COLOUR_RESET}"
     61 	fi
     62 }
     63 
     64 update_mem () {
     65 	memory="${memory_colour} "$(free -m | awk '/Mem:/ {print $3}')MiB"${COLOUR_RESET}"
     66 }
     67 
     68 update_cpu_temp () {
     69 	temp=$(($(cat /sys/class/thermal/thermal_zone2/temp)/1000))
     70 	cpu_temp="${cpu_temp_colour} ""${temp}°C""${COLOUR_RESET}"
     71 }
     72 
     73 update_uptime () {
     74 	uptime="${uptime_colour} "$(~/.local/share/regexghost/panel/uptime)"${COLOUR_RESET}"
     75 }
     76 
     77 update_sunrise () {
     78 	sunrise="${sunrise_colour} "$(~/.local/share/regexghost/panel/sunrise.sh --sunrise --blank)"${COLOUR_RESET}"
     79 }
     80 
     81 update_sunset () {
     82 	sunset="${sunset_colour} "$(~/.local/share/regexghost/panel/sunrise.sh --sunset --blank)"${COLOUR_RESET}"
     83 }
     84 
     85 update_weather () {
     86 	weather_days="$(~/.local/share/regexghost/panel/metoffice.sh)"
     87 	weather_today="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '1q;d')")"
     88 	weather_tomorrow="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '2q;d')")"
     89 	weather_2_days="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '3q;d')")"
     90 	weather="0${weather_today} 1${weather_tomorrow} 2${weather_2_days}"
     91 }
     92 
     93 # This is done by index so I can change the streams checked by just altering the order in the config file
     94 stream_live () {
     95 	streamer_name="$(sed -n "${1}p" "$XDG_CONFIG_HOME/regexghost/streams.csv" | cut -d "," -f 1)"
     96 	first_char="$(echo "$streamer_name" | cut -c 1-1)"
     97 	live="$(stream-check -yn "$streamer_name")"
     98 	if [ "$live" = "y" ]; then
     99 		echo "${first_char} ${stream_live_colour} ${COLOUR_RESET}"
    100 	elif [ "$live" = "w" ]; then
    101 		echo "${first_char} ${stream_not_live_colour} ${COLOUR_RESET}"
    102 	elif [ "$live" = "n" ]; then
    103 		echo "${first_char} ${stream_not_live_colour} ${COLOUR_RESET}"
    104 	else
    105 		echo "${first_char} ${stream_error_colour} ${COLOUR_RESET}"
    106 	fi
    107 }
    108 
    109 update_streams () {
    110 	stream="$(stream_live 1) $(stream_live 2) $(stream_live 3)"
    111 }
    112 
    113 update_music () {
    114 	state="$(mocp -M "$XDG_CONFIG_HOME/moc" -i)"
    115 	song="$(echo "$state" | grep -e "SongTitle" -e "Artist" | tac | tr "\n" "-" | sed 's/-Artist: / - /g' | sed 's/^SongTitle: //g; s/"//g; s/-$//g' | string-trunc 14 ".." | sed 's/ $//g; s/ ..$/../g')"
    116 	pause="$(echo "$state" | grep -e "State" | cut -d " " -f 2 | head -n 1)"
    117 	if [ "$song" = "" ]; then
    118 		music="${music_stopped_colour} N/A${COLOUR_RESET}"
    119 	elif [ "$pause" = "PLAY" ]; then
    120 		music="${music_playing_colour} ${song}${COLOUR_RESET}"
    121 	else
    122 		music="${music_paused_colour} ${song}${COLOUR_RESET}"
    123 	fi
    124 }
    125 
    126 # 
    127 # 
    128 # 
    129 # 
    130 # 
    131 # 
    132 # 
    133 # 
    134 # 
    135 # 
    136 # 
    137 # 
    138 # 
    139 # 
    140 # 
    141 # 
    142 # 
    143 # 
    144 # 
    145 # 
    146 # 
    147 # 
    148 # 
    149 # 
    150 # 
    151 # 
    152 # 
    153 # 
    154 display () {
    155 	echo "%{r} ${music} | ${stream}| ${sunset} | ${sunrise} | ${weather}| ${vol} | ${network_down} | ${wifi} | ${cpu} | ${uptime} | ${cpu_temp} | ${memory} | ${current_time} "
    156 }
    157 
    158 update_vol
    159 update_wifi
    160 update_time
    161 update_sunrise
    162 update_sunset
    163 update_weather
    164 update_streams
    165 update_music
    166 
    167 i=1
    168 
    169 trap "update_vol;display" "RTMIN"
    170 trap "update_music;display" "RTMIN+1"
    171 
    172 while true; do
    173 	sleep 2 & wait && {
    174 		update_network_down
    175 		update_cpu
    176 		update_mem
    177 		update_uptime
    178 		update_cpu_temp
    179 		update_vol
    180 		[ $((i%3)) -eq 0 ] && update_time
    181 		[ $((i%3)) -eq 0 ] && update_wifi
    182 		[ $((i%3)) -eq 0 ] && update_music
    183 		[ $((i % 180)) -eq 0 ] && update_sunset
    184 		[ $((i % 300)) -eq 0 ] && update_sunrise
    185 		[ $((i % 600)) -eq 0 ] && update_streams
    186 		[ $((i % 360)) -eq 0 ] && update_weather
    187 		i=$((i+1))
    188 		[ $i -gt 900 ] && i=0
    189 		display
    190 	}
    191 done