From a2f3ec58f751a493b7a7dd962b5d82ee379d9548 Mon Sep 17 00:00:00 2001 From: Frank Wittig Date: Wed, 9 Apr 2014 12:20:12 +0200 Subject: [PATCH 1/2] autocomplete hosts from hosts sections in ssh-config, two functions to load/unload keys from the agent (e.g. for use in .zshrc) --- plugins/ssh/ssh.plugin.zsh | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 plugins/ssh/ssh.plugin.zsh diff --git a/plugins/ssh/ssh.plugin.zsh b/plugins/ssh/ssh.plugin.zsh new file mode 100644 index 000000000..a308c09b1 --- /dev/null +++ b/plugins/ssh/ssh.plugin.zsh @@ -0,0 +1,39 @@ +############################################################ +# Take all host sections in .ssh/config and offer them for +# completion as hosts (e.g. for ssh, rsync, scp and the like) +# Filter out wildcard host sections. +local hosts +if [[ -f $HOME/.ssh/config ]]; then + hosts=($(cat $HOME/.ssh/config | egrep '^Host.*' | awk '{print $2}' | grep -v '^*' | sed -e 's/\.*\*$//' | grep '\.')) + zstyle ':completion:*:hosts' hosts $hosts +fi + +############################################################ +# Remove host key from known hosts based on a host section +# name from .ssh/config +function ssh_rmhkey { + if [[ "x$1" == "x" ]]; then return; fi + ssh-keygen -R $(grep -A10 $1 ~/.ssh/config | grep -i HostName | head -n 1 | awk '{print $2}') +} +compctl -k hosts ssh_rmhkey + +############################################################ +# Load SSH key into agent +function ssh_load_key() { + local key=$1 + if [[ "$key" == "" ]]; then return; fi + if ( ! ssh-add -l | grep -q $key ); then + ssh-add ~/.ssh/$key; + fi +} + +############################################################ +# Remove SSH key from agent +function ssh_unload_key { + local key=$1 + if [[ "$key" == "" ]]; then return; fi + if ( ssh-add -l|grep -q $key ); then + local keyfile=$(ssh-add -l | grep $key | cut -d ' ' -f 3) + ssh-add -d $keyfile + fi +} From 6aec44a7d307bb2d5b1e5f5e8580aa197d84158f Mon Sep 17 00:00:00 2001 From: Frank Wittig Date: Wed, 9 Apr 2014 12:20:52 +0200 Subject: [PATCH 2/2] autocompletion for clouds tool (https://github.com/cristim/clouds) --- plugins/clouds/_clouds | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 plugins/clouds/_clouds diff --git a/plugins/clouds/_clouds b/plugins/clouds/_clouds new file mode 100644 index 000000000..b7aad1096 --- /dev/null +++ b/plugins/clouds/_clouds @@ -0,0 +1,58 @@ +#compdef clouds +#autoload + +# clouds zsh completion + +_clouds_all_stacks() { + all_stacks=(`clouds list | tail -n +3 | awk '{print $1}'`) +} + +_clouds_local_stacks() { + local_stacks=(`test -d stacks && ls -1 stacks`) +} + +local -a _1st_arguments +_1st_arguments=( + 'clone:Clones an existing stack into a new one' + 'delete:Deletes a stack' + 'dump:Dump CloudFormation stacks from your account into the current directory' + 'edit:Edit a CloudFormation stack locally' + 'help:Shows a list of commands or help for one command' + 'list:List CloudFormation stacks from your account' + 'update:Updated a list of CloudFormation stacks based on information from the current directory' +) + +local expl +local -a all_stacks local_stacks + +_arguments \ + '(-f)--force[Force overwrites of existing data]' \ + '(--help)--help[Show help]' \ + '(--version)--version[Display the program version]' \ + '*:: :->subcmds' && return 0 + +if (( CURRENT == 1 )); then + _describe -t commands "clouds subcommand" _1st_arguments + return +fi + +case "$words[1]" in + clone|edit) + _clouds_local_stacks + _wanted local_stacks expl 'local stacks' compadd -a local_stacks + ;; + update) + _arguments '(-c)--create_missing[Create AWS stacks if the required sources exist locally]' + _clouds_local_stacks + _wanted local_stacks expl 'local stacks' compadd -a local_stacks + ;; + dump) + _arguments '(--all)--all[dump all stacks]' + _clouds_all_stacks + _wanted all_stacks expl 'all stacks' compadd -a all_stacks + ;; + delete) + _clouds_all_stacks + _wanted all_stacks expl 'all stacks' compadd -a all_stacks + ;; +esac