Guest User

Untitled

a guest
Apr 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #!/bin/bash
  2. #Displays input as if someone were typing it
  3. SPEED=4; #default
  4. while getopts "ms:d:" opt; do
  5. case $opt in
  6. s) SPEED=$OPTARG; toggle_speed=2;;
  7. m) toggle_mistakes=1;;
  8. d) dumbness=$OPTARG; toggle_dumbness=2;;
  9. esac
  10. done
  11. if [ $SPEED -lt 1 ] || [ $SPEED -gt 9 ]; then
  12. echo "Speed must be between 1 and 9. 1 is fastest, 9 is slowest"
  13. exit 1
  14. fi
  15. the_input=$*
  16. #add options up then shift that many words to avoid printing the options
  17. shift_amount=$(($toggle_speed + $toggle_mistakes + $toggle_dumbness))
  18. echo $shift_amount
  19. shift $shift_amount
  20. the_input=$*
  21. if [[ x"$*" == x ]]; then
  22. echo "
  23. Usage: typewriter [-ms] <number for speed> \"foo bar baz hello world etc\"
  24. Try 'typewriter --help' for more info.
  25. "
  26. exit 1
  27. fi
  28. if [[ x"$*" == x--help ]] || [[ x"$*" == x--usage ]]; then
  29. echo "
  30. Usage: typewriter [OPTION...][TEXT...]
  31. -s <number> sets the typing speed, [1-9], 1 is fastest, 9 is slowest, default is 4
  32. "
  33. exit 1
  34. fi
  35. if [[ $toggle_mistakes == 1 ]]; then
  36. echo "Mistakes toggled"
  37. fi
  38. while [ -n "$the_input" ]
  39. do
  40. number=$(($RANDOM%$SPEED))
  41. printf "%c" "$the_input"
  42. char_count=$(($char_count + 1))
  43. sleep .$number
  44. if [ $toggle_mistakes == 1 ]; then
  45. alphabet="abcdefghijklmnopqrstuvwxyz"
  46. erase_it=$'\b'
  47. if [[ $char_count == $dumbness ]]; then
  48. echo -n ${alphabet:$(($RANDOM%25)):1}
  49. sleep .$number
  50. echo -n "$erase_it${the_input:$char_count:1}$erase_it"
  51. char_count=0 #reset the count
  52. fi
  53. fi
  54. the_input=${the_input#?}
  55. done
  56. printf "\n"
  57. shit
Add Comment
Please, Sign In to add comment