1 #!/bin/bash
   2 
   3 opts=$(getopt -o niI -l notify,icon,no-icon -- "$@")
   4 eval set -- "$opts"
   5 
   6 while true; do
   7     case $1 in
   8         -n|--notify) shift && notify=1;;
   9         -I|--no-icon) shift && noicon=1;;
  10         -i|--icon) shift && icon=1;;
  11         --) shift && break;;
  12     esac
  13 done
  14 
  15 status=$(
  16 case $1 in
  17     apps) echo ;;
  18     files) echo ;;
  19     browser) echo ;;
  20     kino) echo ;;
  21     bloge) echo  ;;
  22     editor) echo  ;;
  23     mixer) echo ;;
  24     windows) echo ;;
  25     terminal) echo ;;
  26     theme) echo ;;
  27     develop) echo ;;
  28 
  29     mail)
  30         n=$(frm -s new | wc -l)
  31         [[ $n == 0 ]] &&
  32         echo  || echo  $n
  33 
  34         [[ $notify ]] && frm -s new | tac | awk '{ print NR ". " $0 }' |
  35         xargs -r0 notify-send -i emblem-mail Почта
  36     ;;
  37 
  38     news)
  39         n=$(newsboat -x print-unread | cut -d ' ' -f 1)
  40         [[ $n == 0 ]] && n=
  41         echo  $n
  42 
  43         [[ $notify ]] &&
  44         sqlite3 ~/.newsboat/cache.db 'select title from rss_item where unread = 1 order by pubDate desc' |
  45         awk '{ print NR ". " $0 }' | xargs -r0 notify-send -i application-rss+xml Новости
  46     ;;
  47 
  48     network)
  49         d=($(nmcli -g type dev))
  50         i=$(nmcli dev wifi | awk '$1 == "*" { print $8 }')
  51 
  52         [[ $d == wifi ]] &&
  53         i=${i:-} || i=
  54 
  55         echo "$i"
  56 
  57         [[ $notify ]] && (nmcli dev | sed 1d; nmcli dev wifi |
  58         sed '1d; s/^\*\s*/*/; s/^\s*//') | xargs -r0 notify-send -i network Сеть
  59     ;;
  60 
  61     calendar) echo "  $(calcurse -n | sed '1d; s/^\s*//')";;
  62 
  63     music)
  64         s=$(music.sh)
  65         echo "${s:- }"
  66 
  67         [[ $notify && $s ]] && notify-send -i audio-x-generic Музыка "$s"
  68     ;;
  69 
  70     torrents)
  71         s=$(
  72             transmission-remote -l | sed 's/\s\{2,\}/\t/g' |
  73             awk -F \\t '/^\s/ { print substr($(NF - 1), 0, 2) }' |
  74             sed 's/Do\|Up/1 /; s/Se/3 /; s/Qu/4 /; s/Id\|St/5 /' |
  75             sort | uniq -c | awk '{ printf "%s %s ", $3, $1 }'
  76         )
  77         echo "${s:-}"
  78 
  79         [[ $notify ]] &&  transmission-remote -l | sed '1d; $d' |
  80         awk '{ printf "%3s %s\n", $2, $NF }' | xargs -r0 notify-send -i transmission Загрузки
  81     ;;
  82 
  83     weather)
  84         f=~/.cache/weather
  85 
  86         if [[ ! -f $f || $notify ]]; then
  87             read _ _ weather icon desc < <(
  88                 lynx -dump pogoda.ya.ru/saint-petersburg |
  89                 grep -A 3 Сейчас | tr \\n ' ' | tr -d '[]'
  90             )
  91 
  92             curl -s https://yastatic.net/weather/i/icons/funky/light/$icon > $f.svg
  93             notify-send -i $f.svg Погода "$weather ${desc,,}"
  94 
  95             echo "$weather" > $f
  96         fi
  97 
  98         echo " $(< $f)"
  99     ;;
 100 
 101     bday)
 102         s=$(grep "$(date +'%d %b')" ~/Documents/Заметки.md | sed -r 's/\|(\s|$)//g')
 103         n=$(wc -l <<< "$s")
 104 
 105         echo   ${s:+$n}
 106         [[ $notify && $s ]] && notify-send -i x-office-calendar 'Днюха 🎂' "$s"
 107     ;;
 108 
 109     redshift)
 110         [[ $(pgrep -x redshift) ]] &&
 111         echo  || echo 
 112 
 113         [[ $notify ]] && notify-send -i redshift Redshift "$(redshift -p)"
 114     ;;
 115 
 116     lang)
 117         a=([00000]=EN [00001]=RU)
 118         n=$(xset -q | grep -o '0000[0-9]')
 119         echo "${a[$n]}"
 120     ;;
 121 
 122     bandwidth)
 123         a=$(< ~/.cache/status-bandwidth)
 124         b=$(awk '!/lo/ { a+=$2; b+=$10 } END { print a, b }' /proc/net/dev)
 125 
 126         echo $a $b |
 127         awk '{ print ($3 - $1), ($4 - $2) }' |
 128         numfmt --field 1,2 --to iec --suffix B/s
 129 
 130         echo "$b" > ~/.cache/status-bandwidth
 131     ;;
 132 
 133     volume) pacmd list-sinks | awk '/^\s+volume:/ { print $5 }';;
 134 
 135     battery)
 136         declare -A a=(
 137             [Unknown]=
 138            [Critical]=
 139                 [Low]=
 140              [Normal]=
 141                [High]=
 142                [Full]=
 143         )
 144 
 145         for i in /sys/class/power_supply/*; do
 146             echo "${a[$(< $i/capacity_level)]}  $(< $i/model_name)"
 147         done
 148 
 149         [[ $notify ]] &&
 150         paste -d ' ' /sys/class/power_supply/*/{manufacturer,model_name,capacity*} |
 151         xargs -r0 notify-send -i battery Заряд
 152     ;;
 153 
 154     date) date +%c;;
 155     time) date +%R;;
 156 
 157     '') grep -Po '^\s+[\w^)]+\)' $0 | tr -d ') ' | sort;;
 158 esac 2>&- | sed 's/\s*$//g'
 159 )
 160 
 161 [[ $notify ]] && exit
 162 [[ $noicon ]] && echo "${status:2}" && exit
 163 [[ $icon || ${status:2} ]] && echo "$status"