/ tech

Color your Shells

Despite all the Ansibles, Chefs and Puppets you still need to connect to servers / containers etc using SSH from a Terminal every once in a while. To make sure, you are where you're supposed to be, here's a neat little setup that can help you.

phook

phook is a nice little tool that runs a comment after a parent process has finished. Combined with some settings in your .ssh/config and the necessary profiles in iTerm you're never on the wrong server again.

Clone and install.

git clone git@github.com:drinchev/phook.git
cd phook
make
sudo make install

Or simply use brew.

brew tap thefox/brewery
brew install phook

iTerm

For every type of server add a profile and remember the name. For this example I used Prod, Stage and CI.

SSH config

For every server add the following config at ~/.ssh/config.

Host app-prod
HostName 1.2.3.4
User ubuntu
PermitLocalCommand yes
LocalCommand phook -e 'echo "\033]50;SetProfile=Prod\a"' -a 'echo "\033]50;SetProfile=Default\a"'

Host app-stage
HostName 5.6.7.8
User ubuntu
PermitLocalCommand yes
LocalCommand phook -e 'echo "\033]50;SetProfile=Stage\a"' -a 'echo "\033]50;SetProfile=Default\a"'

Host app-ci
HostName 9.0.1.2
User ubuntu
PermitLocalCommand yes
LocalCommand phook -e 'echo "\033]50;SetProfile=CI\a"' -a 'echo "\033]50;SetProfile=Default\a"'

Demo

phook-1