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