Last active
March 9, 2017 22:24
-
-
Save locriani/a11204e6d934f340da06 to your computer and use it in GitHub Desktop.
SSH Terminal Color Hack
This file contains hidden or 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
alias ssh="~/.bash/ssh.sh" |
This file contains hidden or 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
www.example.com | |
list your safe servers on each newline | |
This file lives in your home directory (not in ~/.bash) | |
You need at least one "safe" server in order for the script to function properly |
This file contains hidden or 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
function onExit { | |
osascript ~/.bash/terminal_color.scpt "Pro" | |
} | |
trap onExit EXIT | |
safe_server=`echo "$@" | grep -i --max-count=1 -f ~/.safe_servers | wc -l` | |
if [ $safe_server -gt 0 ]; then | |
osascript ~/.bash/terminal_color.scpt "SafeRemote" | |
else | |
osascript ~/.bash/terminal_color.scpt "Remote" | |
fi | |
/usr/bin/ssh "$@" |
This file contains hidden or 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
on run argv | |
tell application "Terminal" to set current settings of selected tab of window 1 to (first settings set whose name is (item 1 of argv)) | |
end run | |
-- iTerm2 User? | |
-- change the ssh.sh script to use colors instead of theme names and use this AppleScript instead: | |
-- | |
-- on run argv | |
-- tell application "iTerm" to set background color of current session of current terminal to (item 1 of argv) | |
-- end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SSH Terminal Color Hack
This spiffy hack allows you to turn Terminal.app a different color when you SSH into a remote server.
Setup for Terminal.app users
This assumes you are using the
Pro
settings as your default, and will setup aRemote
setting with the changes you want for remote terminals. It also assumes you're using Bash as your shell.Pro
settings twice in Terminal, and name the new settingsRemote
andSafeRemote
.~/.bash
if it doesn't already exist.ssh.sh
andterminal_color.scpt
with the contents above in~/.bash
- make sure they are executable (chmod +x filename
).safe_servers
file in your home directory. This should be a list of servers it is safe to muck around with (playroom / staging servers).alias ssh="~/.bash/ssh.sh"
to your.bash_profile
Setup for iTerm2 users
This assumes you're using Bash as your shell. I also don't use iTerm2, so ymmv.
~/.bash
if it doesn't already exist.ssh.sh
andterminal_color.scpt
with the contents above in~/.bash
- make sure they are executable (chmod +x filename
)terminal_color.scpt
, and replaceSafeRemote
andRemote
inssh.sh
with the background colors you want..safe_servers
file in your home directory. This should be a list of servers it is safe to muck around with (playroom / staging servers).alias ssh="~/.bash/ssh.sh
to your.bash_profile
For more information, check out the blog post at http://developer.teamsnap.com/blog/2015/01/24/terminal-color-scripting/