[download]

local/bin/dwm-status

   1 #!/bin/bash
   2 
   3 source icon
   4 f=/tmp/$$.fifo && mkfifo $f
   5 
   6 trap 'kill $$; exec $0' USR1
   7 trap 'trap - TERM; kill $(jobs -p); rm $f' EXIT INT QUIT TERM
   8 
   9 export MUSIC_FORMAT='$icon -$tl\n'
  10 # export MUSIC_ICON_PLAYING=$(icon music-play)
  11 # export MUSIC_ICON_PAUSED=$(icon music-pause)
  12 
  13 ################################################################################
  14 
  15 kbdd keyboard:En: keyboard:Ru: > $f &
  16 
  17 while true; do
  18     echo "time:$(date +%R):"
  19     echo "music:$(music | paste -sd ' '):"
  20     echo "days:$(days > /dev/null && icon days):"
  21     echo "torrents:$([[ $(torrents | wc -l) != 0 ]] && icon torrents):"
  22 
  23     echo "battery:$(battery | grep -m 1 Charging |
  24     xargs -I % icon battery-% % | awk '{ print $1, $2 }'):"
  25 
  26     sleep 10
  27 done > $f &
  28 
  29 inotifywait -me modify ~/Mail/Inbox 2>&1 | while read; do
  30     echo "inbox:$(icon inbox):"
  31 done > $f &
  32 
  33 inotifywait -me modify ~/.newsboat/cache.db 2>&1 | while read; do
  34     echo "news:$([[ $(news | wc -l) != 0 ]] && icon news):"
  35 done > $f &
  36 
  37 tail -F ~/.cache/music | while read; do
  38     echo "music:$(music | paste -sd ' '):"
  39 done > $f &
  40 
  41 tail -F ~/.cache/weather | while read i _; do
  42     echo "weather:$i:"
  43 done > $f &
  44 
  45 tail -F ~/.cache/volume{,.ico} | while read; do
  46     i=$(icon mixer) # {{{
  47     awk -v i="$i" '{
  48         n = 20
  49         a = int($1 * n / 100)
  50         b = int(n - a)
  51 
  52         printf "volume:%s ", i
  53 
  54         for (i = 0; i < a; i++)
  55             printf "%s", "="
  56 
  57         printf "|"
  58 
  59         for (i = 0; i < b; i++)
  60             printf "%s", "-"
  61 
  62         printf ":\n"
  63     }' ~/.cache/volume # }}}
  64 done > $f &
  65 
  66 while true; do
  67     i=$(icon network) # {{{
  68     a=$(awk '!/lo/ { a+=$2; b+=$10 } END { print a, b }' /proc/net/dev)
  69     sleep 1
  70     b=$(awk '!/lo/ { a+=$2; b+=$10 } END { print a, b }' /proc/net/dev)
  71 
  72     echo "network:$i $(echo "$a $b" | awk '{
  73         a = ($3 - $1) / 1; b = ($4 - $2) / 1
  74         print (a < 1024 ? 0 : a), (b < 1024 ? 0 : b)
  75     }' | numfmt --field 1,2 --to iec --suffix B/s):" # }}}
  76 done > $f &
  77 
  78 ################################################################################
  79 
  80 declare -A mod
  81 status(){ # {{{
  82     local val=${mod[$1]}
  83     status+="$val${val:+$2 }"
  84 } # }}}
  85 update(){
  86     [[ $i == *:* ]] || continue &&
  87     i=${i:0:-1} mod[${i%%:*}]=${i#*:}
  88 
  89     status music ' '
  90 
  91     status weather
  92     status battery
  93     status days
  94 
  95     status torrents
  96     status news
  97     status inbox
  98     status network
  99 
 100     status volume
 101     status+='   '
 102     status keyboard
 103     status+='  '
 104     status time
 105     status+=' '
 106 }
 107 
 108 return 2>&-
 109 while read i; do
 110     status='  ' && update
 111     xsetroot -name "$status"
 112 done < $f