Last active
August 29, 2015 13:57
-
-
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 ;)
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
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