diff options
author | Kenny Woodson <kwoodson@redhat.com> | 2015-02-04 13:37:34 -0500 |
---|---|---|
committer | Kenny Woodson <kwoodson@redhat.com> | 2015-02-04 13:37:34 -0500 |
commit | d124436d94a1e502f7f31a6958d01a513c8cb1a5 (patch) | |
tree | 9e28263456524529072ff8c89034234619e1b56d /bin | |
parent | fe7d30b762357ac4ec1fe2b173320d463267ac82 (diff) | |
download | openshift-d124436d94a1e502f7f31a6958d01a513c8cb1a5.tar.gz openshift-d124436d94a1e502f7f31a6958d01a513c8cb1a5.tar.bz2 openshift-d124436d94a1e502f7f31a6958d01a513c8cb1a5.tar.xz openshift-d124436d94a1e502f7f31a6958d01a513c8cb1a5.zip |
Adding [tab] completion for bash and zsh.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/COMPLETION_SETUP | 25 | ||||
-rw-r--r-- | bin/_ossh_zsh_completion | 20 | ||||
-rwxr-xr-x | bin/ossh | 10 |
3 files changed, 45 insertions, 10 deletions
diff --git a/bin/COMPLETION_SETUP b/bin/COMPLETION_SETUP index c11a2dfff..0183544e6 100644 --- a/bin/COMPLETION_SETUP +++ b/bin/COMPLETION_SETUP @@ -1,17 +1,11 @@ # ossh is an ssh replacement. + Ossh uses a dynamic inventory cache in order to lookup hostnames and translate them to something meaningful such as an IP address or dns name. This allows us to treat our servers as cattle and not as pets. -In order to setup bash completion, source the following script: -/path/to/repository/openshift-online-ansible/bin/ossh_bash_completion - -This bash_completion script will look at the cached version of your -multi_ec2 results in ~/.ansible/tmp/. It will then parse a few -host.env out of the json and return them to be completable. - If you have not run the ossh command and it has not laid down a cache file the completions will not be available. @@ -19,3 +13,20 @@ You can populate the cache by running `ossh --list`. This will populate the cache file and the completions should become available. +This zsh script will look at the cached version of your +multi_ec2 results in ~/.ansible/tmp/. It will then parse a few +{host}.{env} out of the json and return them to be completable. + +# BASH +In order to setup bash completion, source the following script: +/path/to/repository/openshift-online-ansible/bin/ossh_bash_completion + +# ZSH +In order to setup zsh completion, you will need to verify +that the _ossh_zsh_completion script is somewhere in the path +of $fpath. + +Once $fpath includes the _ossh_zsh_completion script then you should +run `exec zsh`. This will then allow you to call `ossh host[TAB]` +for a list of completions. + diff --git a/bin/_ossh_zsh_completion b/bin/_ossh_zsh_completion new file mode 100644 index 000000000..05352bbbb --- /dev/null +++ b/bin/_ossh_zsh_completion @@ -0,0 +1,20 @@ +#compdef ossh + +_ossh_known_hosts(){ + if [[ -f ~/.ansible/tmp/multi_ec2_inventory.cache ]]; then + /usr/bin/python -c 'import json,os; z = json.loads(open("%s"%os.path.expanduser("~/.ansible/tmp/multi_ec2_inventory.cache")).read()); print "\n".join(["%s.%s" % (host["ec2_tag_Name"],host["ec2_tag_environment"]) for dns, host in z["_meta"]["hostvars"].items()])' + fi + +} +_ossh(){ + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments -s : \ + "*:Hosts:_ossh_known_hosts" + + case $state in + *) + +} +_ossh "$@" @@ -26,6 +26,13 @@ class Ossh(object): self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__))) self.parse_cli_args() + # parse host and user + self.process_host() + + if not self.args.list and not self.env: + print "Please specify an environment." + return + if self.args.host == '' and not self.args.list: self.parser.print_help() return @@ -34,15 +41,12 @@ class Ossh(object): self.host_inventory = self.get_hosts() - if self.args.debug: print self.args # get a dict of host inventory self.get_hosts() - # parse host and user - self.process_host() # perform the SSH if self.args.list: |