bins

handy scripts
git clone git://popovic.xyz/bins.git
Log | Files | Refs | LICENSE

bar-weather (784B)


      1 #!/bin/sh
      2 
      3 weather=$HOME/.local/share/status/weather
      4 
      5 getforcast() {
      6     curl -sf wttr.in/$(curl ipinfo.io/loc) > $weather || exit 1;
      7 }
      8 
      9 showweather() {
     10     printf "%s" "$(sed '16q;d' $weather |
     11         grep -wo "[0-9]*%" |\
     12         sort -rn | sed "s/^/☔:/g;1q" | tr -d '\n')"
     13     sed '13q;d' $weather |\
     14         grep -o "m\\([-+]\\)*[0-9]\\+" |\
     15         sort -n -t 'm' -k 2n |\
     16         sed -e 1b -e '$!d' |\
     17         tr '\n|m' ' ' |\
     18         awk '{print " :" $2"("$1")" "°"}' ;
     19 }
     20 
     21 case $BLOCK_BUTTON in
     22     1) setsid -f "$TERMINAL" -e less -Srf "$weather" ;;
     23     3) getforcast && showweather ; pkill -RTMIN+2 dwmblocks ;;
     24     6) "$TERMINAL" -e "$EDITOR" "$0" ;;
     25 esac
     26 
     27 
     28 [ "$(stat -c %y $weather 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
     29 	getforcast
     30 showweather
     31