Created
July 18, 2017 09:40
-
-
Save vglebov/5d0a79f557a49cd964dc9ed0ffde5842 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
HILL1_UPDATE_HOST_SSHT_ADDR="ssh -t user@demo1" | |
HILL2_UPDATE_HOST_SSHT_ADDR="ssh -t user@demo2" | |
HILL3_UPDATE_HOST_SSHT_ADDR="ssh -t user@ci ssh -t user@demo3" | |
HILLS="HILL1 HILL2 HILL3" | |
TARGET_HOSTS="host1 host2 host3" | |
_SSHTargetHostCompletion () { | |
options_1=${HILLS} | |
options_2=${TARGET_HOSTS} | |
options_3="" | |
__CompliteSerial | |
} | |
__CompliteSerial () { | |
COMPREPLY=(); | |
eval "options=\${options_${COMP_CWORD}}" | |
cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=($(compgen -W "${options} " -- ${cur})) | |
return 0 | |
} | |
complete -F _SSHTargetHostCompletion SSHTargetHost | |
# SSHTargetHost HILL2 | |
# SSHTargetHost HILL2 host1 | |
SSHTargetHost () { | |
eval "update_host_ssh_addr=\${$1_UPDATE_HOST_SSHT_ADDR}" | |
if [ "$2" != "" ]; then | |
${update_host_ssh_addr} ssh -t $2 | |
else | |
${update_host_ssh_addr} | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment