Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Displays input as if someone were typing it
- SPEED=4; #default
- while getopts "ms:d:" opt; do
- case $opt in
- s) SPEED=$OPTARG; toggle_speed=2;;
- m) toggle_mistakes=1;;
- d) dumbness=$OPTARG; toggle_dumbness=2;;
- esac
- done
- if [ $SPEED -lt 1 ] || [ $SPEED -gt 9 ]; then
- echo "Speed must be between 1 and 9. 1 is fastest, 9 is slowest"
- exit 1
- fi
- the_input=$*
- #add options up then shift that many words to avoid printing the options
- shift_amount=$(($toggle_speed + $toggle_mistakes + $toggle_dumbness))
- echo $shift_amount
- shift $shift_amount
- the_input=$*
- if [[ x"$*" == x ]]; then
- echo "
- Usage: typewriter [-ms] <number for speed> \"foo bar baz hello world etc\"
- Try 'typewriter --help' for more info.
- "
- exit 1
- fi
- if [[ x"$*" == x--help ]] || [[ x"$*" == x--usage ]]; then
- echo "
- Usage: typewriter [OPTION...][TEXT...]
- -s <number> sets the typing speed, [1-9], 1 is fastest, 9 is slowest, default is 4
- "
- exit 1
- fi
- if [[ $toggle_mistakes == 1 ]]; then
- echo "Mistakes toggled"
- fi
- while [ -n "$the_input" ]
- do
- number=$(($RANDOM%$SPEED))
- printf "%c" "$the_input"
- char_count=$(($char_count + 1))
- sleep .$number
- if [ $toggle_mistakes == 1 ]; then
- alphabet="abcdefghijklmnopqrstuvwxyz"
- erase_it=$'\b'
- if [[ $char_count == $dumbness ]]; then
- echo -n ${alphabet:$(($RANDOM%25)):1}
- sleep .$number
- echo -n "$erase_it${the_input:$char_count:1}$erase_it"
- char_count=0 #reset the count
- fi
- fi
- the_input=${the_input#?}
- done
- printf "\n"
- shit
Add Comment
Please, Sign In to add comment