Skip to content

Instantly share code, notes, and snippets.

@infoslack
Last active August 29, 2015 13:57
Show Gist options
  • Save infoslack/9529553 to your computer and use it in GitHub Desktop.
Save infoslack/9529553 to your computer and use it in GitHub Desktop.
Função para adicionar aliases em .ssh/config de forma fácil. Adicione a função ao seu .bashrc ou similar ;)
ssh-conf(){
if [ $# -lt 2 ]; then
echo "Faz assim: ssh-conf <Host> [<user>@]<hostname>]" >&2
return 1
fi
short=$1
arg=$2
if $(echo "$arg" | grep '@' >/dev/null); then
user=$(echo "$arg"|sed -e 's/@.*$//')
fi
host=$(echo "$arg"|sed -e 's/^.*@//')
if $(grep -i "Host $short" "$HOME/.ssh/config" > /dev/null); then
echo "Esse alias '$short' já existe" >&2
return 1
fi
if [ -z "$host" ]; then
echo "Hostname não encontrado!" >&2
return 1
fi
echo >> "$HOME/.ssh/config"
echo "Host $short" >> "$HOME/.ssh/config"
echo "Hostname $host" >> "$HOME/.ssh/config"
[ ! -z "$user" ] && echo "User $user" >> "$HOME/.ssh/config"
echo "Alias '$short' criado para $host"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment