Change Terminal color when on production machines.

- 2 mins

Many times we are faced with the requirement of sshing into production machines, looking up something from production database or debugging the app. Sometimes the issues are so serious, that we totally forget that we are on production machines and we do some serious breaking shit over there.

So one of the way to clearly differentiate whether you are on a production machine or local can be changing the color of the terminal. Yes, it is possible and it works wonderfully.

This post is about doing such configuration on Iterm2, oh-my-zsh and Mac(Os X El Captain). Ideally, this will remain same for most of the linux systems(but having oh-my-zsh is a requirement as I am using its dot folder).

To begin with, first we will create different color profiles on Iterm 2.

cd ~/.oh-my-zsh/custom
vim iTerm2-ssh.zsh

The contents of the file will be something like

function tabc() {
  NAME=$1; if [ -z "$NAME" ]; then NAME="Default"; fi
  echo -e "\033]50;SetProfile=$NAME\a"

function tab-reset() {
    echo -e "\033]50;SetProfile=$NAME\a"

function colorssh() {
    if [[ -n "$ITERM_SESSION_ID" ]]; then
        trap "tab-reset" INT EXIT
        if [[ "$*" =~ "prod*" ]]; then
            tabc Production
        elif [[ "$*" =~ "stage*" ]]; then
            tabc Staging
            tabc Other
    ssh $*
compdef _ssh tabc=ssh

alias ssh="colorssh"

How is this working?


Taranjeet Singh

Taranjeet Singh

Full Stack Developer, Entrepreneur

comments powered by Disqus
rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora