Advertisement
Guest User

utf8 progress bar

a guest
Sep 1st, 2010
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.81 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # This would be handy as a script to
  4. # produce variable load for testing
  5.  
  6. trap "tput cvvis" EXIT
  7.  
  8. # dash 0.5.5 at least doesn't support \x so we use /usr/bin/
  9. col_base="$(/usr/bin/printf '\x1b')[38;5;"
  10. for i in 229 228 227 226 220 184 178 202 196 160; do
  11.     hlb="$hlb$col_base${i}m▣
  12. "
  13. done
  14.  
  15. rsleep() {
  16.   printf ".1\n.05\n.02\n.01\n" | shuf | tail -n1
  17. }
  18.  
  19. tput civis
  20. col=$(tput bold; tput setaf 3)
  21. nc=$(tput sgr0)
  22. count=0
  23. max=10
  24. inc=1
  25. sleep=.1
  26. while true; do
  27.   left=$(($max-$count))
  28.   hl=$(printf "$hlb" | head -n$count | tr -d '\n')
  29.   nl=$(yes2>/dev/null | head -n$left | tr -d '\n')
  30.   printf "\r$hl$nc$nl"
  31.   sleep $sleep
  32.   count=$(($count+$inc))
  33.   [ "$count" -gt $max ] && { count=$max; inc=-1; sleep=$(rsleep); }
  34.   [ "$count" -lt 0 ] && { count=0; inc=1; sleep=$(rsleep); }
  35. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement