Created
January 25, 2015 18:17
-
-
Save mburgs/eb4132d834aca01cde16 to your computer and use it in GitHub Desktop.
SSH different color based on host from config
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
| ssh() { | |
| #get last argument | |
| for HOST; do true; done | |
| #if it's not an alias just use white | |
| if [[ $HOST == *"@"* ]]; then | |
| COLOR=7 | |
| else | |
| #read in config to find color for alias | |
| #start color from blue | |
| COLOR=1 | |
| while read line; do | |
| if [[ $line == "Host "$HOST* ]]; then | |
| break | |
| elif [[ $line == "Host "* ]]; then | |
| COLOR=$((COLOR+1)) | |
| if [[ $COLOR -gt "6" ]]; then | |
| #don't use white for custom hosts | |
| COLOR=1 | |
| fi | |
| fi | |
| done < ~/.ssh/config | |
| fi | |
| /usr/bin/ssh -t "$*" 'tput bold && tput setf '$COLOR'; bash -l' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment