local/bin/status

   1 #!/bin/bash
   2 
   3 [[ $1 == -i || $1 == --icon ]] &&
   4 shift && suffix=-icon
   5 
   6 [[ $1 == -n || $1 == --notify ]] &&
   7 shift && suffix=-notify
   8 
   9 [[ $1 == -p || $1 == --print ]] &&
  10 shift && suffix=-notify && notify-send(){
  11     [[ $4 ]] && echo "$4"
  12 }
  13 
  14 case $1${1:+$suffix} in
  15     apps-icon) echo ;;
  16     files-icon) echo ;;
  17     browser-icon) echo ;;
  18     kino-icon) echo ;;
  19     bloge-icon) echo ;;
  20     editor-icon) echo ;;
  21     mixer-icon) echo ;;
  22     windows-icon) echo ;;
  23     terminal-icon) echo ;;
  24     theme-icon) echo ;;
  25     develop-icon) echo ;;
  26     symbols-icon) echo ;;
  27     lang-icon) echo גּ;;
  28     volume-icon) echo ;;
  29     battery-icon) echo ;;
  30     bandwidth-icon) echo ;;
  31     calendar-icon) echo ;;
  32     date-icon) echo ;;
  33     time-icon) echo ;;
  34     redshift-icon) [[ $(pgrep -x redshift) ]] && echo  || echo ;;
  35     weather-icon) echo ;;
  36     days-icon) echo ;;
  37     news-icon) echo ;;
  38     music-icon) s=$(music); s=${s:-}; echo "${s%% *}";;
  39     network-icon)
  40         d=($( LANG= nmcli -t -f type,state dev | tr : ' ' ))
  41         [[ ${d[1]} != connected ]] && echo  ||
  42         [[ $d == wifi ]] && echo  || echo 
  43     ;;
  44     picker-icon) echo ;;
  45     nerdfont-icon) echo ;;
  46     dotfiles-icon) echo ;;
  47     notes-icon) echo ;;
  48 
  49     mail)
  50         n=$(frm -s new | wc -l)
  51         [[ $n == 0 ]] && echo  || echo  $n
  52     ;;
  53     mail-notify)
  54         notify-send -i emblem-mail ${1^} "$(
  55             frm -s new | tac | awk '{ print NR ". " $0 }'
  56         )"
  57     ;;
  58 
  59     news)
  60         n=$(newsboat -x print-unread | cut -d ' ' -f 1)
  61         [[ $n == 0 ]] && n=
  62         echo  $n
  63     ;;
  64     news-notify)
  65         notify-send -i application-rss+xml ${1^} "$(
  66             sqlite3 ~/.newsboat/cache.db '
  67                 select title from rss_item where unread = 1
  68                 order by pubDate desc limit 10
  69             ' | awk '{ print NR ". " $0 }'
  70         )"
  71     ;;
  72 
  73     music) echo "$(music | tr \\n ' ')";;
  74     music-notify) notify-send -i audio-x-generic ${1^} "$(music)";;
  75 
  76     torrents)
  77         s=$(
  78             transmission-remote -l | sed 's/\s\+\s/\t/g' |
  79             awk -F \\t '/^\s/ { print substr($(NF - 1), 0, 2) }' |
  80             sed 's/Do\|Up/1 /; s/Se/3 /; s/Qu/4 /; s/Id\|St/5 /' |
  81             sort | uniq -c | awk '{ printf "%s %s ", $3, $1 }' | sed 's/\s*$//'
  82         )
  83         echo "${s:-}"
  84     ;;
  85     torrents-notify)
  86         notify-send -i transmission ${1^} "$(
  87             transmission-remote -l | sed '1d; $d; s/\s\+\s/\t/g' | cut -f 3,9,10 | column -t
  88         )"
  89     ;;
  90 
  91     weather) cut -d ' ' -f 1 ~/.cache/weather;;
  92     weather-notify)
  93         f=~/.cache/weather
  94 
  95         read _ _ weather icon desc < <(
  96             lynx -dump -display_charset utf-8 pogoda.ya.ru/saint-petersburg |
  97             grep -A 3 Сейчас | tr \\n ' ' | tr -d '[]'
  98         )
  99 
 100         echo "${weather:-??°} ${desc,,}" > $f
 101         curl -s https://yastatic.net/weather/i/icons/funky/light/$icon > $f.svg
 102 
 103         notify-send -i $f.svg ${1^} "$(< $f)"
 104     ;;
 105 
 106     days)
 107         n=$(grep "$(date +'%d %b')" ~/Documents/Дни.md | wc -l)
 108         [[ $n != 0 ]] && echo  $n
 109     ;;
 110     days-notify)
 111         notify-send -i x-office-calendar "🎂 ${1^}" "$(
 112             cat  ~/Documents/Дни.md | tr \| \\t | sort |
 113             awk 'int($1) >= int(strftime("%d")) && index($2, strftime("%b")) {
 114                 print
 115 
 116                 if (int($1) == int(strftime("%d"))) {
 117                     gsub(/\S/, "-")
 118                     print
 119                 }
 120             }' | column -te
 121         )"
 122     ;;
 123 
 124     *-notify) notify-send ${1^} "???";;
 125     *-icon) s=$($0 ${1/-icon}); echo "${s%% *}";;
 126 
 127     '') grep -Po "^\s+[\w^)]+$suffix\)" $0 | tr -d ') ' | sort;;
 128 esac 2>&-