In my job, I have to ssh to loads of different machines. To make my life easier, I have been trying to set the colorscheme of each machine automatically so that I can tell at a glance which one I happen to be working on.
It is almost working.
~/.ssh/config:
Host some-remote-server
Hostname some-remote-server.ac.uk
User myusername
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes
ForwardX11 yes
Host some-other-remote-server
Hostname some-other-remote-server.ac.uk
User myusername
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes
ForwardX11 yes
ProxyCommand ssh -Y some-remote-server -W %h:%p
ControlMaster auto
ControlPath /tmp/ssh-socket-%r@%h-%p
ControlPersist 600
Let's pretend I want both "some-remote-server" and "some-other-remote-server" to be blue and I want "my-local-server" to be red.
Logging in is no problem; there is some code in "~/.profile" which sets the colorscheme appropriately. However, logging out is problematic.
~/.bash_logout:
if [[ $- == *i* ]]; then
ORIGIN_HOST=`who am i | awk -F"[()]" '{print $2}'`
$HOME/bin/set_the_colorscheme $ORIGIN_HOST
fi
When I exit an ssh session from my-local-server to some-other-remote-server, the above script identifies $ORIGIN_HOST as "some-remote-server" (b/c of the ControlMaster setting in my SSH config file) and so the colors stay blue.
Is there anyway to detect that I am using ControlMaster and find the host that issued the original ssh command?
Thanks.