summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-08-16 22:57:43 -0300
committerSilvio Rhatto <rhatto@riseup.net>2013-08-16 22:57:43 -0300
commit004f0b0f950d0c8e43e2a4d59638fa152138dc71 (patch)
treeba33edcd17b511424a6b5134712c2beeab00951b /lib
parent26dbb6af9ebf1d55b1543ff4db86f83f2a59307d (diff)
downloadkeyringer-004f0b0f950d0c8e43e2a4d59638fa152138dc71.tar.gz
keyringer-004f0b0f950d0c8e43e2a4d59638fa152138dc71.tar.bz2
Matching zsh with bash completion
Diffstat (limited to 'lib')
-rw-r--r--lib/keyringer/completions/zsh/_keyringer82
1 files changed, 76 insertions, 6 deletions
diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer
index 1f1c250..3aba2b3 100644
--- a/lib/keyringer/completions/zsh/_keyringer
+++ b/lib/keyringer/completions/zsh/_keyringer
@@ -1,5 +1,32 @@
#compdef keyringer
+# Completion for git subcommand
+_keyringer_git_complete() {
+ if [ -e "/etc/bash_completion.d/git" ]; then
+ (
+ source /etc/bash_completion.d/git
+ cd $path
+ COMP_WORDS=(git $*)
+ COMP_CWORD=$((${#COMP_WORDS[*]} - 1))
+
+ if [ "$COMP_CWORD" == "0" ]; then
+ COMP_CWORD=1
+ fi
+
+ _git
+
+ LAST=${COMP_WORDS[COMP_CWORD]}
+ REPLY=${COMPREPLY[@]}
+
+ if [ "$REPLY" == "$LAST" ]; then
+ return
+ fi
+
+ echo ${COMPREPLY[@]}
+ )
+ fi
+}
+
_keyringer() {
local curcontext="$curcontext" state line
typeset -A opt_args
@@ -8,10 +35,12 @@ _keyringer() {
local config="$HOME/.keyringer"
local keyrings="`ls $config | sed -e 's/config//'`"
- _arguments \
- '1: :->keyring'\
- '2: :->action'\
- '*: :->options'
+ _arguments \
+ '1: :->keyring' \
+ '2: :->action' \
+ '3: :->options' \
+ '4: :->misc' \
+ '*: :->final'
case $state in
keyring)
@@ -20,9 +49,50 @@ _keyringer() {
action)
compadd "$@" `keyringer $words[2] commands`
;;
+ options)
+ case $words[3] in
+ options|preferences)
+ compadd "$@" ls edit add
+ ;;
+ recipients)
+ compadd "$@" ls edit
+ ;;
+ ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|recrypt)
+ # TODO: do not rely on bash
+ compadd "$@" $(bash -c "set -f && keyringer $words[2] ls -p -d $words[4]*" 2> /dev/null)
+ ;;
+ genpair)
+ compadd "$@" gpg ssh ssl ssl-self
+ ;;
+ git)
+ compadd "$@" $(_keyringer_git_complete $words[4])
+ ;;
+ *)
+ ;;
+ esac
+ ;;
+ misc)
+ case "$words[3]" in
+ recipients)
+ compadd "$@" $(cd $path/config/recipients && ls -p $words[5]* 2> /dev/null)
+ ;;
+ genpair)
+ # TODO: do not rely on bash
+ compadd "$@" $(bash -c "set -f && keyringer $instance ls -p -d $words[5]*" 2> /dev/null)
+ ;;
+ git)
+ # TODO
+ compadd "$@" $(_keyringer_git_complete $words[4] $words[5])
+ ;;
+ *)
+ ;;
+ esac
+ ;;
*)
- # TODO
- true
+ if [ $words[3] == "$git" ]; then
+ # TODO
+ true
+ fi
;;
esac
}