From 1046b1ebcb3bf0841636d2215faf95ddf1895b47 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 12 Jul 2013 23:56:40 -0300 Subject: More on completion --- lib/keyringer/completions/bash | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 6de93bb..2d6fd29 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -3,27 +3,39 @@ # _keyringer() { - local cur prev opts + # Standard stuff + local cur prev opts config COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" # Initial options - opts="`ls $HOME/.keyringer | sed -e 's/config//'`" + config="$HOME/.keyringer" + opts="`ls $config | sed -e 's/config//'`" - # Available keyrings - keyrings="`echo $opts | sed -e 's/ /|/'`" + # Available instances + instances="`echo $opts | sed -e 's/ /|/'`" - # The current keyring - keyring="${COMP_WORDS[1]}" + # The current instance + instance="${COMP_WORDS[1]}" # Command completions - if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$keyrings]"; then - opts="`keyringer $keyring commands`" - else + if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then + opts="`keyringer $instance commands`" + elif [ "${#COMP_WORDS[@]}" == "4" ]; then + # Process config + source $config/config + case "${prev}" in + options|preferences) + opts="ls edit add" + ;; + recipients) + opts="ls edit" + ;; ls) - opts="`keyringer $keyring ls ${cur}`" + # TODO + opts="`keyringer $instance ls ${cur}`" ;; *) ;; -- cgit v1.2.3