make it so that -Sy<tab> doesn't end up as -y
---
 contrib/zsh_completion.in | 321 ++++++++++++++++++++++++++++------------------
 1 file changed, 194 insertions(+), 127 deletions(-)

diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in
index 84ee93c..4d1766e 100644
--- a/contrib/zsh_completion.in
+++ b/contrib/zsh_completion.in
@@ -117,11 +117,10 @@ _pacman_action_query() {
        local context state line
        typeset -A opt_args
 
-#      _arguments -s : \
-#              "$_pacman_opts_common[@]" \
-#              "$_pacman_opts_query_actions[@]" \
-#              "$_pacman_opts_query_modifiers[@]"
-
+       _arguments -s : \
+               "$_pacman_opts_common[@]" \
+               "$_pacman_opts_query_actions[@]" \
+               "$_pacman_opts_query_modifiers[@]"
        case $state in
                query_file)
                        _arguments -s : \
@@ -143,6 +142,7 @@ _pacman_action_query() {
                                ;;
                query_search)
                        _arguments -s : \
+                               "$_pacman_opts_query_actions[@]" \
                                "$_pacman_opts_common[@]" \
                                "$_pacman_opts_query_modifiers[@]" \
                                '*:search text: '
@@ -169,10 +169,10 @@ _pacman_action_sync() {
        local context state line
        typeset -A opt_args
 
-#      _arguments -s : \
-#              "$_pacman_opts_common[@]" \
-#              "$_pacman_opts_sync_actions[@]" #\
-#              #"$_pacman_opts_sync_modifiers[@]"
+       _arguments -s : \
+               "$_pacman_opts_common[@]" \
+               "$_pacman_opts_sync_actions[@]" \
+               "$_pacman_opts_sync_modifiers[@]"
 
        case $state in
                sync_clean)
@@ -285,51 +285,116 @@ _pacman_get_command() {
        done
 }
 
-# main dispatcher
+_sync_shortopts=(
+    '-S[sync command]'
+    '+b[set an alternate database location]'
+    '+c[remove old packages from cache directory (-cc for all)]'
+    '-d[skip dependency version checks (-dd to skip all checks)]'
+    '-g[view all members of a package group]'
+    '*-i[view package information]'
+    '+l[view a list of packages in a repo]'
+    '-p[print the targets instead of performing the operation]'
+    '-q[show less information for query and search]'
+    '+r[set an alternate installation root]'
+    '+s[search remote repositories for matching strings]'
+    '-u[upgrade installed packages (-uu allows downgrade)]'
+    '-v[be verbose]'
+    '-w[download packages but do not install/upgrade anything]'
+    '*-y[download fresh package databases from the server]'
+)
+
+_query_shortopts=(
+    '-Q[query command]'
+    '+b[an alternate database location]'
+    '-c[view the changelog of a package]'
+    '-d[list packages installed as dependencies]'
+    '-e[list packages explicitly installed]'
+    '+g[view all members of a package group]'
+    '*-i[view package information (-ii for backup files)]'
+    '-k[check that the files owned by the package(s) are present]'
+    '-l[list the contents of the queried package]'
+    '-m[list installed packages not found in sync db(s)]'
+    '-n[list installed packages only found in sync db(s)]'
+    '+o[query the package that own <file>]'
+    '+p[query a package file instead of the database]'
+    '-q[show less information for query and search]'
+    '+r[set an alternate installation root]'
+    '+s[search locally-installed packages for matching strings]'
+    '-t[list packages not required by any package]'
+    '-u[list outdated packages]'
+    '-v[be verbose]'
+    )
+
+
+_pacman_maincomp(){
+    case $1 in
+        -Q*g) # ipkg groups
+            _arguments -s : \
+                "$_pacman_opts_common[@]" \
+                "$_pacman_opts_query_modifiers[@]" \
+                '*:groups:_pacman_completions_installed_groups'
+                ;;
+        -Q*o) # file
+            _arguments -s : \
+                "$_pacman_opts_common[@]" \
+                "$_pacman_opts_query_modifiers[@]" \
+                '*:package file:_files'
+                ;;
+        -Q*p) # file *.pkg.tar*
+            _arguments -s : \
+                "$_pacman_opts_common[@]" \
+                "$_pacman_opts_query_modifiers[@]" \
+                '*:package file:_files -g "*.pkg.tar*"'
+                ;;
+        -Q*b)
+            _arguments -s : \
+                "$_pacman_opts_common[@]" \
+                "$_pacman_opts_query_modifiers[@]" \
+                '*:package file:_files -/'
+                ;;
+        -Q*r)
+            _arguments '*:change root:_files -/'
+            ;;
+        -Q*s)
+            _message "regex";
+            ;; 
+        -Q*)  _pacman_action_query    ;;
+        -R*)  _pacman_action_remove   ;;
+        -S*c*) # no completion
+            return 0
+            ;;
+        -S*l) # repos
+            _arguments -s : \
+                "$_pacman_opts_common[@]" \
+                "$_pacman_opts_sync_modifiers[@]" \
+                '*:package repo:_pacman_completions_repositories' \
+                ;;
+        -S*g) # pkg groups
+            _arguments -s : \
+                "$_pacman_opts_common[@]" \
+                "$_pacman_opts_sync_modifiers[@]" \
+                '*:package group:_pacman_completions_all_groups'
+                ;;
+        -S*)  _pacman_action_sync     ;;
+        -U*)  _pacman_action_upgrade  ;;
+        -V*)  _pacman_action_version  ;;
+        -h*)  _pacman_action_help     ;;
+        -  )  _pacman_action_none     ;;
+        *  )  _pacman_action_sync     ;;
+    esac
+}
 _pacman_zsh_comp() {
-       case $words[2] in
-               -Q*g*) # ipkg groups
-                       _arguments -s : \
-                               "$_pacman_opts_common[@]" \
-                               "$_pacman_opts_query_modifiers[@]" \
-                               '*:groups:_pacman_completions_installed_groups'
-                               ;;
-               -Q*o*) # file
-                       _arguments -s : \
-                               "$_pacman_opts_common[@]" \
-                               "$_pacman_opts_query_modifiers[@]" \
-                               '*:package file:_files'
-                               ;;
-               -Q*p*) # file *.pkg.tar*
-                       _arguments -s : \
-                               "$_pacman_opts_common[@]" \
-                               "$_pacman_opts_query_modifiers[@]" \
-                               '*:package file:_files -g "*.pkg.tar*"'
-                               ;;
-               -Q*)  _pacman_action_query    ;;
-               -R*)  _pacman_action_remove   ;;
-               -S*c*) # no completion
-                       return 0
-                       ;;
-               -S*l*) # repos
-                       _arguments -s : \
-                               "$_pacman_opts_common[@]" \
-                               "$_pacman_opts_sync_modifiers[@]" \
-                               '*:package 
repo:_pacman_completions_repositories' \
-                               ;;
-               -S*g*) # pkg groups
-                       _arguments -s : \
-                               "$_pacman_opts_common[@]" \
-                               "$_pacman_opts_sync_modifiers[@]" \
-                               '*:package group:_pacman_completions_all_groups'
-                               ;;
-               -S*)  _pacman_action_sync     ;;
-               -U*)  _pacman_action_upgrade  ;;
-               -V*)  _pacman_action_version  ;;
-               -h*)  _pacman_action_help     ;;
-               -  )  _pacman_action_none     ;;
-               *  )  return 1                ;;
-       esac
+    varcur="${(M)#words:#-*}"
+    if (( varcur == 1 )) && (( CURRENT < 3 )); then
+        case ${(M)words:#-*} in
+            -S*) _arguments -s -w "$_sync_shortopts[@]" ;;
+            -Q*) _arguments -s -w "$_query_shortopts[@]" ;;
+        esac
+    else
+        if _pacman_maincomp ${${(M)words:#-*}[-1]} ; then
+            _pacman_maincomp $words[2]
+        fi
+    fi
 }
 
 _key_shortopts=(
@@ -373,39 +438,39 @@ _pacman_key_options=(
   )
 
 _pacman_key() {
-  case $words[CURRENT] in
-    --*)
-      _arguments -s : \
-        "$_pacman_key_options[@]" \
-        "$_key_longopts[@]"
-      ;;
-    -*)
-      _arguments -s : \
-        "$_pacman_key_options[@]" \
-        "$_key_shortopts[@]" \
-        "$_key_longopts[@]"
-      ;;
-    *)
-      i=$#;
-      while [[ $words[$i] != -* ]] && [[ $words[$i] != "pacman-key" ]];do
-        i=$(($i-1))
-      done
-      case $i in
-        --*)
-        _arguments -s : \
-          "$_pacman_key_options[@]" \
-          "$_key_longopts[@]"
-        ;;
-      -*)
-        _arguments -s : \
-          "$_pacman_key_options[@]" \
-          "$_key_shortopts[@]" \
-          "$_key_longopts[@]"
-        ;;
-      *) return 1;;
-    esac
-    ;;
-  esac
+       case $words[CURRENT] in
+               --*)
+                       _arguments -s : \
+                               "$_pacman_key_options[@]" \
+                               "$_key_longopts[@]"
+                       ;;
+               -*)
+                       _arguments -s : \
+                               "$_pacman_key_options[@]" \
+                               "$_key_shortopts[@]" \
+                               "$_key_longopts[@]"
+                       ;;
+               *)
+                       i=$#;
+                       while [[ $words[$i] != -* ]] && [[ $words[$i] != 
"pacman-key" ]];do
+                               i=$(($i-1))
+                       done
+                       case $i in
+                               --*)
+                                       _arguments -s : \
+                                               "$_pacman_key_options[@]" \
+                                               "$_key_longopts[@]"
+                                       ;;
+                               -*)
+                                       _arguments -s : \
+                                               "$_pacman_key_options[@]" \
+                                               "$_key_shortopts[@]" \
+                                               "$_key_longopts[@]"
+                                       ;;
+                               *) return 1;;
+                       esac
+                       ;;
+       esac
 }
 
 _keys() {
@@ -487,49 +552,51 @@ _makepkg_longopts=(
   '--noprogressbar[Do not show a progress bar when downloading files]'
   )
 _makepkg(){
-    case $words[CURRENT] in
-      -*)
-        _arguments -s -w : \
-          "$_makepkg_shortopts[@]" \
-          "$_makepkg_longopts[@]"
-        ;;
-      --* )
-        _arguments -s \
-          "$_makepkg_longopts[@]"
-        ;;
-      - )_makepkg_action_none ;;
-      * )
-        i=$#
-        while [[ $words[i] != -* ]] && [[ $words[$i] != "makepkg" ]];do
-          i=$((i-1));
-        done
-        case $words[$i] in
-          -*)
-            _arguments -s -w : \
-              "$_makepkg_shortopts[@]" \
-              "$_makepkg_longopts[@]"
-            ;;
-          --* )
-            _arguments -s \
-              "$_makepkg_longopts[@]"
-            ;;
-          - )_makepkg_action_none ;;
-          * ) return 1 ;;
-        esac
-      ;;
-    esac
+       case $words[CURRENT] in
+               -*)
+                       _arguments -s -w : \
+                               "$_makepkg_shortopts[@]" \
+                               "$_makepkg_longopts[@]"
+                       ;;
+               --* )
+                       _arguments -s \
+                               "$_makepkg_longopts[@]"
+                       ;;
+               - )_makepkg_action_none ;;
+       * )
+               i=$#
+               while [[ $words[i] != -* ]] && [[ $words[$i] != "makepkg" ]];do
+                       i=$((i-1));
+               done
+               case $words[$i] in
+                       -*)
+                               _arguments -s -w : \
+                                       "$_makepkg_shortopts[@]" \
+                                       "$_makepkg_longopts[@]"
+                               ;;
+                       --* )
+                               _arguments -s \
+                                       "$_makepkg_longopts[@]"
+                               ;;
+                       - )_makepkg_action_none ;;
+               * ) return 1 ;;
+       esac
+       ;;
+       esac
 }
 _pacman_comp() {
-  case "$service" in
-    makepkg)
-      _makepkg "$@";;
-    pacman-key)
-      _pacman_key "$@";;
-    pacman)
-      _pacman_zsh_comp "$@";;
-    *)
-      _message "Error";;
-  esac
+       case "$service" in
+               makepkg)
+                       _makepkg "$@";;
+               pacman-key)
+                       _pacman_key "$@";;
+               pacman)
+                       _pacman_zsh_comp "$@";;
+               *)
+                       _message "Error";;
+       esac
 }
 
 _pacman_comp "$@"
+
+#vim: set ft=zsh ts=4 sw=4 et
-- 
1.8.0.1


Reply via email to