zsh-workers
 help / color / mirror / code / Atom feed
cd3f41127b38ca5af4d10e2fe4f5163529691f6b blob 6002 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
 
#compdef zypper
#
# Copyright (C) 2009 Holger Macht <holger@homac.de>
# Copyright (C) 2014 Thomas Mitterfellner <thomas.mitterfellner@gmail.com>
# Copyright (C) 2014 Mariusz Fik <fisiu@opensuse.org>
#
# This file is released under the GPLv2.
#
# Based on the zsh guide from http://zsh.dotsrc.org/Guide/zshguide06.html
#
# Toggle verbose completions: zstyle ':completion:*:zypper:*' verbose no
#                             zstyle ':completion:*:zypper-subcommand:*' verbose no
#
#  version 0.3
#
# Main dispatcher

_zypper_caching_policy() {
    # rebuild if cache is absent or older than zypper's
    [[ ! /var/cache/zypp/raw -ot "$1" ]]
}

_zypper() {
    typeset -A opt_args
    local curcontext="$curcontext"

    if (( CURRENT > 2 )) && [[ ${words[2]} != "help" ]]; then
        # Remember the subcommand name
        local cmd=${words[2]}
        # Set the context for the subcommand.
        curcontext="${curcontext%:*:*}:zypper-$cmd"
        # Narrow the range of words we are looking at to exclude `zypper'
        (( CURRENT-- ))
        shift words

        _zypper_cmd_do $cmd
    else
        local hline
        local -a cmdlist
        local tag=0
        _call_program help-commands LANG=C zypper help | sed -e ':a;N;$!ba;s/\n\t\t\t\t/ /g' | while read -A hline; do
            # start parsing with "Global Options:"
            [[ $hline =~ "^Global Options:" ]] && tag=1
            [[ $tag = 0 ]] && continue
            # skip empty lines
            [[ $hline =~ ^\s*$ ]] && continue
            # all commands have to start with lower case letters
            [[ $hline == [[:upper:]]* ]] && continue
            (( ${#hline} < 2 )) && continue

            # cut comma at end of command
            hline[1]=`echo $hline[1] | sed -e 's/\(^.*\),/\1/'`

            # ${hline[1]%,} truncates the last ','
            cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}")
        done
        _describe -t zypper-commands 'zypper command' cmdlist
    fi
}

_all_repos() {
    local -a repos
    repos=( $(zypper -q lr | tail -n +3 | cut -d'|' -f 2) )
    _describe -t repos 'available repository' repos && return
}

_enabled_repos() {
    repos=( $(zypper -x lr | grep 'enabled="1"' | cut -d\" -f 2) )
    _describe -t repos 'available repository' repos && return
}

_disabled_repos() {
    repos=( $(zypper -x lr | grep 'enabled="0"' | cut -d\" -f 2) )
    _describe -t repos 'available repository' repos && return
}

_zypper_cmd_do() {
    typeset -A opt_args
    local expl
    local hline
    local -a cmdlist
    local tag=0

    zstyle ":completion:${curcontext}:" use-cache on
    zstyle ":completion:${curcontext}:" cache-policy _zypper_caching_policy

    _call_program help-commands LANG=C zypper help $cmd | while read -A hline; do
        # start parsing from "Options:"
        [[ $hline =~ "^Command options:" ]] && tag=1
        [[ $tag = 0 ]] && continue
        # Option has to start with a '-'
        [[ $hline[1] =~ ^- ]] || continue
        (( ${#hline} < 2 )) && continue

        cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}")
    done

    if [ -n "$cmdlist" ]; then
        local -a repos

        # special completion lists for certain options (mainly repos)
        case ${words[CURRENT - 1]} in
            --from)
                repos=( $(zypper -x lr | grep 'enabled="1"' | cut -d\" -f 2) )
                _describe -t repos 'available repository' repos && return
               ;;
            (--enable|-e)
                case $cmd in
                    (mr|modifyrepo) 
                        _disabled_repos && return
                    ;;
                esac
                ;;
            (--disable|-d)
                case $cmd in
                    (mr|modifyrepo) 
                        _enabled_repos && return
                    ;;
                esac
                ;;
            (--type|-t)
                local -a types
                case $cmd in
                    (if|info|se|search|in|install) 
                        types=( pattern srcpackage package patch )
                        _describe -t types 'package type' types && return
                    ;;
                esac
                ;;
        esac

        # all options available for the active main command
	_describe -t zypper-commands 'zypper command' cmdlist

        case $cmd in
            (lr|repos)
                _all_repos
                ;;
            (in|install)
                _description files expl 'RPM files' 
                _files "$expl[@]" -g '*.(#i)rpm(-.)'
                ;;
        esac
        
        # only suggest packages if at least one character is given
        if [[ ${words[CURRENT]} =~ "^[0-9a-zA-Z]" ]] ; then
          local -a pkglist

	  if (( ! $+_cache_zypp_all_raw[1] )) && { _cache_invalid zypper-all-raw ||
	      ! _retrieve_cache zypper-all-raw }
          then
              _cache_zypp_all_raw=$(zypper -x -q se | grep '<solvable' | cut -d \" -f 2,4)
              _cache_zypp_all=( $(echo $_zypp_all_raw | grep 'installed' | cut -d\" -f 2) )
              _cache_zypp_not_installed=( $(echo $_zypp_all_raw | grep 'not-installed' | cut -d\" -f 2 ) )
              _cache_zypp_installed=( $(echo $_zypp_all_raw | grep '^installed' | cut -d\" -f 2 ) )
              _store_cache zypper-all-raw _cache_zypp_all_raw _cache_zypp_all \
		  _cache_zypp_not_installed _cache_zypp_installed
          fi

          case $cmd in
              (in|install)
                  pkglist=( $_cache_zypp_not_installed )
                  _wanted packaged expl package compadd -a pkglist
                  ;;
              (rm|remove|up|update)
                  pkglist=( $_cache_zypp_installed )
                  compadd -a pkglist
                  ;;
              (if|info|se|search)
                  pkglist=( $_cache_zypp_all )
                  compadd -a pkglist
                  ;;
          esac
        fi
    else
	_complete
    fi
}

# Code to make sure _zypper is run when we load it
_zypper "$@"
debug log:

solving cd3f411 ...
found cd3f411 in https://inbox.vuxu.org/zsh-workers/6472.1481623850@hydra.kiddle.eu/
found 25a32c3 in https://git.vuxu.org/mirror/zsh/
preparing index
index prepared:
100644 25a32c3f18a2de70bddfe95049beddd1a456c0b0	Completion/openSUSE/Command/_zypper

applying [1/1] https://inbox.vuxu.org/zsh-workers/6472.1481623850@hydra.kiddle.eu/
diff --git a/Completion/openSUSE/Command/_zypper b/Completion/openSUSE/Command/_zypper
index 25a32c3..cd3f411 100644

Checking patch Completion/openSUSE/Command/_zypper...
Applied patch Completion/openSUSE/Command/_zypper cleanly.

index at:
100644 cd3f41127b38ca5af4d10e2fe4f5163529691f6b	Completion/openSUSE/Command/_zypper

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).