Skip to content

Instantly share code, notes, and snippets.

@nicola-strappazzon
Last active July 10, 2019 09:58
Show Gist options
  • Save nicola-strappazzon/af873f14461e643c7f7a3493b83d8cd6 to your computer and use it in GitHub Desktop.
Save nicola-strappazzon/af873f14461e643c7f7a3493b83d8cd6 to your computer and use it in GitHub Desktop.
Send local env variables to server through by ssh
_ssh_completions()
{
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$(grep '^Host' ~/.ssh/config ~/.ssh/config.d/* 2>/dev/null | grep -v '[?*]' | cut -d ' ' -f 2-)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
complete -F _ssh_completions s
s() {
if [ -n "${1}" ] ; then
MYSQL_USER=root
MYSQL_PASSWORD=
case $1 in
*-stg-*) MYSQL_PASSWORD=foo ;;
*-sbx-*) MYSQL_PASSWORD=bar ;;
*-prd-*) MYSQL_PASSWORD=baz ;;
esac
/usr/bin/ssh $1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment