]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Shell completion: adding 'init' subcommand
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 29 Sep 2013 21:43:10 +0000 (18:43 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 29 Sep 2013 21:43:10 +0000 (18:43 -0300)
lib/keyringer/completions/bash/keyringer
lib/keyringer/completions/zsh/_keyringer

index ccc18512a124d07ad83a60376f561ca9260e3ca4..875e6ab36227fa900ead0a74ae0dbf855c464d01 100644 (file)
@@ -60,20 +60,22 @@ _keyringer() {
 
   # Process config
   source $config/config
-  path="`eval echo '$'$instance`"
-  keyrings="`ls --color=never $config | sed -e 's/config//'`"
+  keyrings="`ls --color=never $config | sed -e 's/config//' | xargs`"
 
   # Available instances
-  instances="`echo $keyrings | sed -e 's/ /|/'`"
+  instances="`echo $keyrings | sed -e 's/ /\\\|/g'`"
 
   # The current instance
   instance="${COMP_WORDS[1]}"
+  path="`eval echo '$'$instance`"
 
   # Command completions
   if [ "${#COMP_WORDS[@]}" == "2" ]; then
     opts="$keyrings"
-  elif [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then
+  elif [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "$instances"; then
     opts="`export KEYRINGER_CHECK_VERSION=false && keyringer $instance commands`"
+  elif [ "${#COMP_WORDS[@]}" == "3" ]; then
+    opts="init"
   elif [ "${#COMP_WORDS[@]}" == "4" ]; then
     case "${prev}" in
       options|preferences)
@@ -91,6 +93,13 @@ _keyringer() {
       git)
         opts="$(_keyringer_git_complete ${cur})"
         ;;
+      init)
+        # Thanks http://unix.stackexchange.com/questions/55520/create-bash-completion-script-to-autocomplete-paths-after-is-equal-sign
+        cur=${cur//\\ / }
+        [[ ${cur} == "~/"* ]] && cur=${cur/\~/$HOME}
+
+        opts="$(compgen -o dirnames ${cur})"
+        ;;
       *)
         ;;
     esac
index 47a83fccbbd701c11046d6dd43502509735a4998..119d26db39636490291d652f6fc5d2323538f0e6 100644 (file)
@@ -20,8 +20,9 @@ _keyringer() {
 
     # Process config
     source $config/config
-    local keyrings="`ls --color=never $config | sed -e 's/config//'`"
+    local keyrings="`ls --color=never $config | sed -e 's/config//' | xargs`"
     local keyring_path="`eval echo '$'$words[2]`"
+    local instances="`echo $keyrings | sed -e 's/ /\\\|/g'`"
 
     _arguments        \
       '1: :->keyring' \
@@ -35,7 +36,11 @@ _keyringer() {
         _arguments "1:Keyrings:($keyrings)"
         ;;
       action)
-        compadd "$@" `KEYRINGER_CHECK_VERSION=false keyringer $words[2] commands`
+        if echo $words[2] | grep -qe "$instances"; then
+          compadd "$@" `KEYRINGER_CHECK_VERSION=false keyringer $words[2] commands`
+        else
+          compadd "$@" "init"
+        fi
         ;;
       options)
         case $words[3] in
@@ -54,6 +59,9 @@ _keyringer() {
           git)
             compadd "$@" $(_keyringer_git_complete $words[4])
             ;;
+          init)
+            _files
+            ;;
           *)
             ;;
         esac