Skip to content

Instantly share code, notes, and snippets.

@henrytseng
Last active October 26, 2018 01:30
Show Gist options
  • Save henrytseng/1a1714b0cabb36bf5708b444fb35312a to your computer and use it in GitHub Desktop.
Save henrytseng/1a1714b0cabb36bf5708b444fb35312a to your computer and use it in GitHub Desktop.
# Changing iTerm2 color in MacOSX when SSHing (so you know at a glance that you're no longer in Kansas)
# Adapted from https://gist.github.com/porras/5856906
# 1. Create a theme in your terminal setting with the name "SSH" and the desired colors, background, etc.
# 2. Add this to your .bash_profile (or .bashrc, I always forget the difference ;))
# 3. Optional but useful: in the terminal, go to Settings > Startup and set "New tabs open with" to
# "default settings" (otherwise, if you open a new tab from the changed one, you get a local tab with
# the SSH colors)
function tabc() {
NAME=$1; if [ -z "$NAME" ]; then NAME="Default"; fi # if you have trouble with this, change
# "Default" to the name of your default theme
echo -e "\033]50;SetProfile=$NAME\a"
}
function colorssh() {
tabc _SSH
/usr/bin/ssh $*
tabc
}
function colorpsql() {
tabc _PSQL
/usr/local/bin/psql $*
tabc
}
alias ssh="colorssh"
alias psql="colorpsql"
# This would be easy to extend to check if a theme with the name of the server exists and set it, and
# fall back to the SSH theme. This way you can have different colors for different remote environments
# (per project, production, staging, etc.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment