20 lines
546 B
Bash
Executable File
20 lines
546 B
Bash
Executable File
#!/bin/bash
|
|
|
|
#
|
|
# Draws a ping pong cursor what prints out the contents of "man bash" or any other stdout it gets piped.
|
|
#
|
|
# Uses:
|
|
# $ pingpong.sh echo "My very long string"
|
|
# $ pingpong.sh cat path/to/text/file
|
|
#
|
|
|
|
ARGS=$@;
|
|
LINES=$(tput lines)
|
|
COLUMNS=$(tput cols)
|
|
AWK_MAGIC='BEGIN{x=y=e=f=1}{if(x==mx||!x){e*=-1};if(y==my||!y){f*=-1};x+=e;y+=f;printf "\033[%s;%sH%s",y,x,$1;for (a=0;a<400000;a++){}}';
|
|
|
|
if [ $# -eq 0 ]; then ARGS='man bash'; fi
|
|
|
|
bash -c "$ARGS" \
|
|
| sed 's/./&\n/g' \
|
|
| awk -v mx=$COLUMNS -v my=$LINES "$AWK_MAGIC" |