Skip to content

Instantly share code, notes, and snippets.

@mburgs
Created January 25, 2015 18:17
Show Gist options
  • Select an option

  • Save mburgs/eb4132d834aca01cde16 to your computer and use it in GitHub Desktop.

Select an option

Save mburgs/eb4132d834aca01cde16 to your computer and use it in GitHub Desktop.
SSH different color based on host from config
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