Last active
October 12, 2016 09:45
-
-
Save rk295/606c6a7e80ff4f39e81f306832a508eb to your computer and use it in GitHub Desktop.
If you use [consul](https://www.consul.io/) this will add a bash auto complete function to help you ssh to servers shown by `consul members list`
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
# | |
# consul_ssh-completion.sh | |
# | |
# Adds all servers returned by `consul members list` to the ssh command as | |
# tab completion candidates. | |
# | |
# Usage: | |
# | |
# curl -OL https://gist.githubusercontent.com/rk295/606c6a7e80ff4f39e81f306832a508eb/raw/825a539d6693a6c0535110e7c7a88d1211234e63/consul_ssh-completion.sh ; . consul_ssh-completion.sh | |
# | |
# | |
# Author: Robin Kearney <robin@kearney.co.uk> | |
# Date: 21/04/2016 | |
# | |
# | |
_consul_ssh() | |
{ | |
local cur prev opts | |
consulPath=$(command -v consul) | |
# Catch case where consul can't be found. | |
if [[ $? -ne 0 ]]; then | |
return 0 | |
fi | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
opts=$(consul members -status=alive | grep -v ^Node | cut -d ' ' -f 1) | |
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) | |
return 0 | |
} | |
complete -F _consul_ssh ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Curl the raw version of this file (url) and then source it:
Maybe add it to
/etc/bash_completion.d/
or wherever your distro puts such things or source it from your personal profile.