Skip to content

Instantly share code, notes, and snippets.

@AlexMeuer
Last active June 22, 2018 11:14
Show Gist options
  • Save AlexMeuer/9911ebe6cb0498e8caf81ee82745b181 to your computer and use it in GitHub Desktop.
Save AlexMeuer/9911ebe6cb0498e8caf81ee82745b181 to your computer and use it in GitHub Desktop.
Pipe some input to and set sail! UPDATE: Now works on MacOS (tested with iTerm) and no longer clutters terminal history! :D
#!/bin/bash
# Name: set_sail
#
# Description: This is a little script to make terminal output less dull.
# Just direct stuff into the scripts stdin and you'll set sail!
# Output can be slowed by passing --slow or -s as the first argument, you can also,
# optionally, specify how long to wait between outputs if using the slow options.
#
# Example use: cat <some_file> | set_sail --slow 1
# apt-get update | set_sail
#
# Author: Alexander Meuer | AlexMeuer.github.io
# Define colours!
SPEECH="\033[92m"
SHIP="\033[33m"
HORIZON="\033[36m"
WATER="\033[34m"
DEFAULT="\033[39m"
ERASE_LINE="\033[2K"
# See if the user wants to slow down the output.
if [[ "$1" == "-s" || "$1" == "--slow" ]]; then
SLOW=true
if [[ -n "$2" ]] && [[ $2 -gt 0 ]]; then
SLEEP_TIME=$2;
else
SLEEP_TIME=0.5
fi
else
SLOW=false
fi
# Draws the greeting and the ship, with colours. Also draws the water that touches the ship.
drawShip() {
echo
echo -e "${ERASE_LINE}${SPEECH} ${GREETING}"
echo
echo
echo -e "${SHIP} | | |"
echo " )_) )_) )_)"
echo " )___))___))___)"
echo " )____)____)_____)\\"
echo " _____|____|____|____\\\__"
echo -e "${HORIZON}---------${SHIP}\\ /${HORIZON}---------"
echo -e "${WATER} ^^ ^ ^^^^^^^^^^^^^^^^^^^^^^"
}
# Draws the water, moving the "waves" back as the ship sails onward unto adventure.
COUNTER_START=6
COUNTER=$COUNTER_START
drawWater() {
echo -en "${ERASE_LINE}${WATER}"
INDEX=0
while [ $INDEX -lt $COUNTER ]; do
echo -n " "
let INDEX=$INDEX+1
done
echo "^^^^ ^^^^ ^^^ ^^"
echo -ne "${ERASE_LINE}"
INDEX=0
while [ $INDEX -lt $COUNTER ]; do
echo -n " "
let INDEX=$INDEX+1
done
echo " ^^^^ ^^^"
if [ $COUNTER -eq 0 ]; then
COUNTER=${COUNTER_START}
else
let COUNTER=$COUNTER-1
fi
}
drawAll() {
GREETING=${line}
drawShip
drawWater
if $SLOW; then
sleep $SLEEP_TIME
fi
}
if read line; then
drawAll
fi
# Read stdin, update the greeting text and redraw everything.
while read line; do
echo -en "\033[13A" # Jump back up the 13 lines we printed
drawAll
done < /dev/stdin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment