Skip to content

Instantly share code, notes, and snippets.

@hypergig
Created November 6, 2017 16:42
Show Gist options
  • Save hypergig/c581777bde9c3118c805142adfc7eb77 to your computer and use it in GitHub Desktop.
Save hypergig/c581777bde9c3118c805142adfc7eb77 to your computer and use it in GitHub Desktop.
color echo for bash
#!/usr/bin/env bash
# add colorized echos as functions
declare -A colors
colors=(
# black
[bla]='0;30'
# red
[r]='0;31'
# green
[g]='0;32'
# brown/orange
[o]='0;33'
# blue
[blu]='0;34'
# purple
[p]='0;35'
# cyan
[c]='0;36'
# light gray
[lgra]='0;37'
# dark gray
[dgra]='1;30'
# light red
[lr]='1;31'
# light green
[lgre]='1;32'
# yellow
[y]='1;33'
# light blue
[lblu]='1;34'
# light purple
[lp]='1;35'
# light cyan
[lc]='1;36'
# white
[w]='1;37'
)
for c in "${!colors[@]}"
do
eval "${c}echo() { echo -e \"\033[${colors[$c]}m\$@\033[0m\"; }"
done
@hypergig
Copy link
Author

hypergig commented Nov 6, 2017

This script adds a whole bunch of fun new echos to your shell. Just source this file and type pecho hello for a purple hello. See line 6 for all the different types of echos you get!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment