Created
May 30, 2016 19:17
-
-
Save rebeccacremona/ca6efdadd9eb3511f5fcc636b4c39d64 to your computer and use it in GitHub Desktop.
Automatically change Terminal profiles when ssh'ing into a server, and return to your default on exiting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# terminal profiles & ssh | |
# uses 'Pro' as default | |
function extractServerName () { echo ${1} | cut -f1 -d "."; } | |
function setTerminal() { PROFILE=${1}; osascript -e "try" -e "tell app | |
\"Terminal\" to set current settings of first window to settings set | |
\"${PROFILE}\"" -e "end try"; } | |
function ssh() { | |
if command ssh "$@"; then | |
setTerminal pro | |
fi | |
} | |
export -f extractServerName | |
export -f setTerminal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In Terminal preferences, create a new profile (or import this example, which has my preferred settings | |
for a production web server). The new profile's name must match the first part of the server's address. | |
For example, the profile for myserver.example.edu should be named "myserver". | |
Add the two snippets to your bash profile and ssh config, and enjoy. The profile will switch when ssh | |
is used internally by commands such as rsync as well as in interactive shell sessions. | |
I find that occasionally, Terminal will not switch back to my default profile after exiting an ssh | |
session. I don't yet know why. If that happens, just run "setTerminal pro", to switch to your desired | |
profile. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### in .ssh/config ### | |
Host * | |
PermitLocalCommand yes | |
LocalCommand setTerminal $(extractServerName %h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>BackgroundColor</key> | |
<data> | |
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS | |
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECww | |
LjQ3ODI2MDg3IDAuMTQ1MTA0MzYgMC4xMTY4ODEyMSAwLjg1MDAwMDAyABABgALSEBES | |
E1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVk | |
QXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztBSE5bYpGTlZqlrra5wtTX3AAAAAAAAAEB | |
AAAAAAAAABkAAAAAAAAAAAAAAAAAAADe | |
</data> | |
<key>Bell</key> | |
<true/> | |
<key>CursorColor</key> | |
<data> | |
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS | |
AAGGoKMHCA9VJG51bGzTCQoLDA0OV05TV2hpdGVcTlNDb2xvclNwYWNlViRjbGFzc0Ix | |
ABADgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3Rf | |
EA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztBSFBdZGdpa3B7hIyPmKqt | |
sgAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAAC0 | |
</data> | |
<key>CursorType</key> | |
<integer>1</integer> | |
<key>Font</key> | |
<data> | |
YnBsaXN0MDDUAQIDBAUGGBlYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS | |
AAGGoKQHCBESVSRudWxs1AkKCwwNDg8QVk5TU2l6ZVhOU2ZGbGFnc1ZOU05hbWVWJGNs | |
YXNzI0AwAAAAAAAAEBCAAoADXU1lbmxvLVJlZ3VsYXLSExQVFlokY2xhc3NuYW1lWCRj | |
bGFzc2VzVk5TRm9udKIVF1hOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEaG1Ryb290 | |
gAEIERojLTI3PEJLUltiaXJ0dniGi5afpqmyxMfMAAAAAAAAAQEAAAAAAAAAHAAAAAAA | |
AAAAAAAAAAAAAM4= | |
</data> | |
<key>FontAntialias</key> | |
<true/> | |
<key>FontWidthSpacing</key> | |
<real>1.004032258064516</real> | |
<key>ProfileCurrentVersion</key> | |
<real>2.04</real> | |
<key>SelectionColor</key> | |
<data> | |
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS | |
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECMw | |
LjIzNzkwMzIxIDAuMDk3NjAxMzM5IDAuMDg3NDM0NTIzABACgALSEBESE1okY2xhc3Nu | |
YW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLR | |
FxhUcm9vdIABCBEaIy0yNztBSE5bYoiKjJGcpa2wucvO0wAAAAAAAAEBAAAAAAAAABkA | |
AAAAAAAAAAAAAAAAAADV | |
</data> | |
<key>TextBoldColor</key> | |
<data> | |
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS | |
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBww | |
Ljg3NSAwLjc0MDM4ODQ1IDAuMTMyMTM4NzMAEAGAAtIQERITWiRjbGFzc25hbWVYJGNs | |
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290 | |
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA | |
AAAAAAAAAM4= | |
</data> | |
<key>TextColor</key> | |
<data> | |
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS | |
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECEw | |
Ljg0MzEzNzMyIDAuNzg4MjM1MzcgMC42NTQ5MDE5OAAQAoAC0hAREhNaJGNsYXNzbmFt | |
ZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hpdmVy0RcY | |
VHJvb3SAAQgRGiMtMjc7QUhOW2KGiIqPmqOrrrfJzNEAAAAAAAABAQAAAAAAAAAZAAAA | |
AAAAAAAAAAAAAAAA0w== | |
</data> | |
<key>VisualBell</key> | |
<false/> | |
<key>fontAllowsDisableAntialias</key> | |
<integer>0</integer> | |
<key>name</key> | |
<string>myserver</string> | |
<key>type</key> | |
<string>Window Settings</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment