Last active
June 20, 2020 20:18
-
-
Save gravitymonkey/0624ad146a13095e366c8e9644a766f5 to your computer and use it in GitHub Desktop.
Terminal App setup for diff colors per environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get .colors.csv from here, drop it in your ~ directory | |
# https://gist.github.com/avillafiorita/9e626ce370e1da6c6373/revisions | |
# add this to .bash_profile | |
# remember to source .bash_profile before you use it. | |
# Wrapping ssh command with extra functionality | |
ssh() { | |
# If hostname starts with a given string (in my case, the environment name), change bg color | |
HOSTNAME=`echo $@` | |
echo $HOSTNAME | |
if [[ $HOSTNAME = stage* ]] | |
then | |
set_background_color DarkSeaGreen4 | |
set_foreground_color ivory1 | |
fi | |
if [[ $HOSTNAME = sandbox* ]] | |
then | |
set_background_color wheat1 | |
set_foreground_color black | |
fi | |
if [[ $HOSTNAME = prod* ]] | |
then | |
set_background_color red | |
set_foreground_color white | |
fi | |
# Call original ssh command | |
if command ssh "$@" | |
then | |
# on exit change back to your default | |
set_background_color LightGrey | |
set_foreground_color DarkSlateGrey | |
fi | |
} | |
# | |
# Colors for Apple Terminal | |
# | |
function list_colors { | |
cat ${HOME}/.colors.csv | |
} | |
function grep_apple_color { | |
grep "$*" ${HOME}/.colors.csv | |
} | |
function get_apple_color { | |
egrep "(^|,)$*(,|\t)" ${HOME}/.colors.csv | cut -f 6 | |
} | |
function set_foreground_color { | |
color=$(get_apple_color $*) | |
if [ "$color" != "" ] ; then | |
osascript -e "tell application \"Terminal\" to set normal text color of window 1 to ${color}" | |
echo "Text: $*" | |
fi | |
} | |
function set_background_color { | |
color=$(get_apple_color $*) | |
if [ "$color" != "" ] ; then | |
osascript -e "tell application \"Terminal\" to set background color of window 1 to ${color}" | |
echo "Background: $*" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment