Skip to content

Instantly share code, notes, and snippets.

@ambirdsall
Created August 16, 2024 20:42
Show Gist options
  • Save ambirdsall/7afaaff08eb2aa71ab58c7fadd61182e to your computer and use it in GitHub Desktop.
Save ambirdsall/7afaaff08eb2aa71ab58c7fadd61182e to your computer and use it in GitHub Desktop.
#!/bin/bash
frames=(
"
_______ _______
0__o. /______//______/| @_o
/\_, /______//______/ /\\
| \ | || | / |
"
"
. _______ _______
o_ 0 /______//______/| @_o
/\_, /______//______/ /\\
| \ | || | / |
"
"
o ___.___ _______
\_ 0 /______//______/| @_o
/\_, /______//______/ /\\
| \ | || | / |
"
"
o _______ _______
\_ 0 /______//._____/| @_o
/\_, /______//______/ /\\
| \ | || | / |
"
"
o _______ _______
\_ 0 /______//______/| @_o
/\_, /______//___.__/ /\\
| \ | || | / |
"
"
o _______ _______
\_ 0 /______//_____./| o@
/\_, /______//______/ /\\
| \ | || | / |
"
"
o _______ _______
\_ 0 /______//______/|.o_@
/\_, /______//______/ /\\
| \ | || | / |
"
"
o _______ ______.
\_ 0 /______//______/| o@
/\_, /______//______/ /\\
| \ | || | / |
"
"
o _______ .______
\_ 0 /______//______/| @_o
/\_, /______//______/ /\\
| \ | || | / |
"
"
o _______ _______
\_ 0 /____._//______/| @_o
/\_, /______//______/ /\\
| \ | || | / |
"
"
_______ _______
o_ 0 /______//______/| @_o
/\_, /_.____//______/ /\\
| \ | || | / |
"
"
_______ _______
0_o . /______//______/| @_o
/\_, /______//______/ /\\
| \ | || | / |
"
)
display_help () {
echo "Usage: $0 [<frame_number> | -C | --clear]"
echo "This script displays an animated ASCII art of a ping pong rally."
echo ""
echo "Options:"
echo " <frame_number> Display a specific animation frame. No clearing is done automatically."
echo " -C, --clear Clear the previous 4 lines without displaying a frame."
echo " -h, --help Show this help message."
}
if [[ $# -eq 0 ]]; then
while true; do
for frame in "${frames[@]}"; do
clear
echo "$frame"
sleep 0.2
done
done
exit 0
fi
clear_flag=false
frame_index=-1
# Parse arguments
for arg in "$@"; do
if [[ $arg == "--clear" || $arg == "-C" ]]; then
clear_flag=true
elif [[ $arg =~ ^[0-9]+$ ]]; then
frame_index=$((arg % ${#frames[@]}))
elif [[ $arg == "-h" || $arg == "--help" ]]; then
display_help
exit 0
else
display_help
exit 1
fi
done
# Clear the previous frame if the --clear/-C flag is present
if $clear_flag; then
echo -ne "\033[5A" # Move the cursor up 5 lines
echo -ne "\033[0J" # Clear from the cursor to the end of the screen
fi
# Display the frame if a valid frame index was given
if [[ $frame_index -ge 0 ]]; then
echo -ne "${frames[$frame_index]}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment