Custom terminal tab title and ssh on mac

In case you are using ssh private keys to connect to remote Linux servers on cloud, it is better to automation connection to various machines using bash script. I often connect to EC2 machines from my local macbook. Here is a sample script (you can save it as myssh.sh) you can use to connect to a remote linux machine:

ssh -i /somepath/private_key.pem $1

Now to connect to prod1.infoheap.com, you can use the following command:

$ myssh.sh prod1.infoheap.com

When you open multiple tabs and connect to various machine, the following bash code can be used in myssh.sh script:

#!/bin/bash
printf "\e]1;`echo $* | sed -Ee 's/^.+\@//'`\a"
TERM=vt100 ssh -i /somepath/private_key.pem $*
printf "\e]1;bash\a"

You can customize it as per your need. Note that the code to set the tab title uses escape and bell char as shown below:

$ printf "\e]1;SOME_VALUE\a"
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments