Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
903 B

  1. #!/usr/bin/env bash
  2. if ! command -v bc > /dev/null 2>&1; then
  3. printf "%s\n" "You must have the 'bc' package installed to run this program"
  4. fi
  5. snowflakes=(❄ ❅ ❆)
  6. width=$(tput cols)
  7. platform=$(uname -s)
  8. if [ $platform = 'Linux' ]; then
  9. cpu_count=$(grep -ic ^processor /proc/cpuinfo);
  10. elif [ $platform = 'Darwin' ]; then
  11. cpu_count=$(sysctl -n hw.ncpu)
  12. fi
  13. while true; do
  14. if [ $platform = 'Linux' ]; then
  15. load=$(cut -d ' ' -f 1 /proc/loadavg)
  16. elif [ $platform = 'Darwin' ]; then
  17. load=$(sysctl -n vm.loadavg | cut -d ' ' -f 2)
  18. fi
  19. heaviness=$(echo "scale=10;$load/$cpu_count" | bc)
  20. rand_col=$(( (RANDOM % width) + 1 ))
  21. printf "%${rand_col}s\n" "${snowflakes[$(( (RANDOM % ${#snowflakes[*]}) ))]}"
  22. if [ "$(echo "$heaviness > 1" | bc -l)" -eq 1 ]; then
  23. sleep "$(echo "scale=10;1/$heaviness" | bc)"
  24. else
  25. sleep .75
  26. fi
  27. done