xsetroot.sh 944 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #! /bin/bash
  2. SEP="|"
  3. # If we're in a cron job, we need to set up an environment,
  4. # and if we're not in a cron job, the variable $- will contain the letter "i".
  5. [[ $- == *i* ]] || {
  6. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$HOME/bin
  7. }
  8. convert_percent_to_bar() {
  9. nboxes=10
  10. filled=$(echo "($1+5)/$nboxes" | bc)
  11. unfilled=$(echo $nboxes-$filled | bc)
  12. echo -n $(yes ■ | head -$filled | tr '\n' ' ' | sed 's/ //g')
  13. echo -n $(yes □ | head -$unfilled | tr '\n' ' ' | sed 's/ //g')
  14. }
  15. register=()
  16. xsetrootd="$HOME"/xsetroot.d
  17. for f in "${xsetrootd}"/*; do
  18. . "$f"
  19. done
  20. while true; do
  21. nfuns=${#register[*]}
  22. statusline=""
  23. if (( nfuns != 0 )); then
  24. statusline="$(${register[0]})"
  25. fi
  26. if (( nfuns > 1 )); then
  27. for fn in ${register[@]/${register[0]}}; do
  28. statusline+="${SEP}$($fn)"
  29. done
  30. fi
  31. xsetroot -name "$statusline"
  32. sleep 1
  33. done