[download]

local/bin/dwm-status

   1 #!/bin/bash
   2 
   3 [[ $1 == -d ]] &&
   4 setsid -f $0 && exit
   5 
   6 f=~/.cache/${0##*/}
   7 [[ -p $f ]] || mkfifo $f
   8 
   9 source icon
  10 declare -A mod
  11 
  12 trap 'exit' INT TERM
  13 trap 'kill 0' EXIT
  14 
  15 sleep(){ # {{{
  16     read -t $1 <> <(:)
  17 } # }}}
  18 status(){ # {{{
  19     [[ $# == 2 ]] &&
  20     echo "$1:$2:" && return
  21 
  22     local mod=${mod[$1]}
  23     status+="$mod${mod:+ }"
  24 } # }}}
  25 battery(){ # {{{
  26     command battery | grep -i 'charging\|unknown' |
  27     icon -x battery | awk '{ print $1, $3 }' | paste -sd ' '
  28 } # }}}
  29 temperature(){ # {{{
  30     command temperature | grep '°C' | sort -k 2r |
  31     icon -x temperature | awk '$3 > 50 { print $1, $3 }' |
  32     paste -sd ' '
  33 } # }}}
  34 torrents(){ # {{{
  35     command torrents | sort -k 2n | sed 1q |
  36     icon -x torrents | awk '{ print $1, $3 }'
  37 } # }}}
  38 
  39 ################################################################################
  40 
  41 xkbstate keyboard:En: keyboard:Ru: > $f &
  42 
  43 while true; do status temperature "$(temperature)";     sleep 30; done > $f &
  44 while true; do status torrents    "$(torrents)";        sleep 20; done > $f &
  45 while true; do status time        "$(printf '%(%T)T')"; sleep 1;  done > $f &
  46 while true; do status days        "$(days  > /dev/null && icon days)";  sleep 55; done > $f &
  47 
  48 while true; do
  49     status inbox "$(icon inbox)"
  50     inbox > /dev/null && notify inbox
  51     inotifywait -qqe close_write ~/Почта/Входящие || sleep 5
  52 done > $f &
  53 
  54 while true; do
  55     status news "$(news > /dev/null && icon news)"
  56     inotifywait -qqe close_write ~/.newsboat/cache.db || sleep 5
  57 done > $f &
  58 
  59 while true; do
  60     status weather "$(weather | sed 1q | cut -d ' ' -f 1)"
  61     inotifywait -qqe close_write ~/.cache/weather || sleep 5
  62 done > $f &
  63 
  64 while true; do
  65     awk -v i="$(icon mixer)" '{ # {{{
  66         n = 20
  67         a = int($1 * n / 100)
  68         b = int(n - a)
  69 
  70         printf "volume:%s ", i
  71 
  72         for (i = 0; i < a; i++)
  73             printf "%s", "="
  74 
  75         printf "|"
  76 
  77         for (i = 0; i < b; i++)
  78             printf "%s", "-"
  79 
  80         printf ":\n"
  81     }' ~/.cache/volume # }}}
  82     inotifywait -qqe close_write ~/.cache/volume || sleep 5
  83 done > $f &
  84 
  85 while true; do
  86     a=$(awk '!/lo/ { a+=$2; b+=$10 } END { print a, b }' /proc/net/dev) # {{{
  87     sleep 1
  88     b=$(awk '!/lo/ { a+=$2; b+=$10 } END { print a, b }' /proc/net/dev)
  89 
  90     status network "$(icon network) $(echo "$a $b" | awk '{
  91         a = ($3 - $1) / 1; b = ($4 - $2) / 1
  92         print (a < 1024 ? 0 : a), (b < 1024 ? 0 : b)
  93     }' | numfmt --field 1,2 --to iec --suffix B/s)" # }}}
  94 done > $f &
  95 
  96 while true; do
  97     while read i; do
  98         [[ $i == *added* ]] && break
  99         status battery "$(battery)"
 100     done < <(upower -m || sleep 10)
 101 done > $f &
 102 
 103 while true; do
 104     inotifywait -t 5 -qqe close_write ~/.cache/player
 105     [[ $? == 1 ]] && sleep 5
 106     status player "$(player -f '$icon $tl' | sed 1q)"
 107 done > $f & player > /dev/null &
 108 
 109 while true; do
 110     inotifywait -t 25 -qqe close_write ~/.cache/e3372
 111     [[ $? == 1 ]] && sleep 25
 112     status e3372 "$(e3372 > /dev/null && icon e3372)"
 113 done > $f & e3372 > /dev/null &
 114 
 115 ################################################################################
 116 
 117 update(){
 118     [[ $i == *:*: ]] &&
 119     i=${i:0:-1} mod[${i%%:*}]=${i#*:}
 120 
 121     status='  '
 122 
 123     status text
 124     status player
 125 
 126     status weather
 127     status temperature
 128     status battery
 129     status days
 130 
 131     status torrents
 132     status news
 133     status inbox
 134     status e3372
 135     status network
 136 
 137     status volume
 138     status+='   '
 139     status keyboard
 140     status+='  '
 141     status time
 142 }
 143 
 144 return 2>&-
 145 while read i; do
 146     update
 147     xsetroot -name "$status"
 148 done < $f