- Update zsh-update-zypper-completion.patch to v0.3

OBS-URL: https://build.opensuse.org/package/show/shells/zsh?expand=0&rev=129
This commit is contained in:
Ismail Dönmez 2014-01-17 09:42:38 +00:00 committed by Git OBS Bridge
parent 27bcc0a928
commit 7fa8ba6e31
2 changed files with 131 additions and 74 deletions

View File

@ -1,31 +1,31 @@
Index: zsh-5.0.4/Completion/openSUSE/Command/_zypper Index: zsh-5.0.5/Completion/openSUSE/Command/_zypper
=================================================================== ===================================================================
--- zsh-5.0.4.orig/Completion/openSUSE/Command/_zypper --- zsh-5.0.5.orig/Completion/openSUSE/Command/_zypper
+++ zsh-5.0.4/Completion/openSUSE/Command/_zypper +++ zsh-5.0.5/Completion/openSUSE/Command/_zypper
@@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#compdef zypper #compdef zypper
# #
# Copyright (C) 2009 Holger Macht <holger@homac.de> # Copyright (C) 2009 Holger Macht <holger@homac.de>
+# Copyright (C) 2013 Thomas Mitterfellner <thomas.mitterfellner@gmail.com> +# Copyright (C) 2014 Thomas Mitterfellner <thomas.mitterfellner@gmail.com>
# #
# This file is released under the GPLv2. # This file is released under the GPLv2.
# #
@@ -9,11 +10,23 @@ @@ -9,60 +10,169 @@
# Toggle verbose completions: zstyle ':completion:*:zypper:*' verbose no # Toggle verbose completions: zstyle ':completion:*:zypper:*' verbose no
# zstyle ':completion:*:zypper-subcommand:*' verbose no # zstyle ':completion:*:zypper-subcommand:*' verbose no
# #
-# version 0.1 -# version 0.1
+# version 0.2 +# version 0.3
# #
# Main dispatcher # Main dispatcher
+function _zypper_caching_policy () { +function _zypper_caching_policy () {
+ # rebuild if cache is more than a week old + # rebuild if zsh's cache is older than zypper's
+ if test /var/cache/zypp/raw -nt "$1"; then + if test /var/cache/zypp/raw -nt "$1"; then
+ return 0 + return 0
+ else + else
+ return 1 + return 1
+ fi + fi
+} +}
+ +
_zypper() { _zypper() {
@ -34,17 +34,57 @@ Index: zsh-5.0.4/Completion/openSUSE/Command/_zypper
+ +
if (( CURRENT > 2 )) && [[ ${words[2]} != "help" ]]; then if (( CURRENT > 2 )) && [[ ${words[2]} != "help" ]]; then
# Remember the subcommand name # Remember the subcommand name
local cmd=${words[2]} - local cmd=${words[2]}
@@ -22,7 +35,7 @@ _zypper() { + local cmd=${words[2]}
# Set the context for the subcommand.
- curcontext="${curcontext%:*:*}:zypper-subcommand"
+ curcontext="${curcontext%:*:*}:zypper-subcommand"
# Narrow the range of words we are looking at to exclude `zypper' # Narrow the range of words we are looking at to exclude `zypper'
(( CURRENT-- )) - (( CURRENT-- ))
shift words - shift words
- -
- _zypper_cmd_do $cmd
+ (( CURRENT-- ))
+ shift words
+ +
_zypper_cmd_do $cmd + _zypper_cmd_do $cmd
else else
local hline - local hline
@@ -46,10 +59,33 @@ _zypper() { - 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
- # all commands have to start with lower case letters
- [[ $hline[1] =~ ^[A-Z] ]] && 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
+ 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
+ # all commands have to start with lower case letters
+ [[ $hline[1] =~ ^[A-Z] ]] && 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 fi
} }
@ -76,9 +116,21 @@ Index: zsh-5.0.4/Completion/openSUSE/Command/_zypper
+ zstyle ":completion:${curcontext}:" cache-policy _zypper_caching_policy + zstyle ":completion:${curcontext}:" cache-policy _zypper_caching_policy
+ +
_call_program help-commands LANG=C zypper help $cmd | while read -A hline; do _call_program help-commands LANG=C zypper help $cmd | while read -A hline; do
# start parsing from "Options:" - # start parsing from "Options:"
[[ $hline =~ "^Command options:" ]] && tag=1 - [[ $hline =~ "^Command options:" ]] && tag=1
@@ -62,7 +98,81 @@ _zypper_cmd_do() { - [[ $tag = 0 ]] && continue
- # Option has to start with a '-'
- [[ $hline[1] =~ ^- ]] || continue
- (( ${#hline} < 2 )) && continue
+ # 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]}")
+ cmdlist=($cmdlist "${hline[1]%,}:${hline[2,-1]}")
done done
if [ -n "$cmdlist" ]; then if [ -n "$cmdlist" ]; then
@ -86,47 +138,47 @@ Index: zsh-5.0.4/Completion/openSUSE/Command/_zypper
+ +
+ # special completion lists for certain options (mainly repos) + # special completion lists for certain options (mainly repos)
+ case ${words[CURRENT - 1]} in + case ${words[CURRENT - 1]} in
+ --from) + --from)
+ repos=( $(zypper -x lr | grep 'enabled="1"' | cut -d\" -f 2) ) + repos=( $(zypper -x lr | grep 'enabled="1"' | cut -d\" -f 2) )
+ _describe -t repos 'Available repositories' repos && return + _describe -t repos 'Available repositories' repos && return
+ ;; + ;;
+ (--enable|-e) + (--enable|-e)
+ case $cmd in + case $cmd in
+ (mr|modifyrepo) + (mr|modifyrepo)
+ _disabled_repos && return + _disabled_repos && return
+ ;; + ;;
+ esac + esac
+ ;; + ;;
+ (--disable|-d) + (--disable|-d)
+ case $cmd in + case $cmd in
+ (mr|modifyrepo) + (mr|modifyrepo)
+ _enabled_repos && return + _enabled_repos && return
+ ;; + ;;
+ esac + esac
+ ;; + ;;
+ (--type|-t) + (--type|-t)
+ local -a types + local -a types
+ case $cmd in + case $cmd in
+ (if|info|se|search|in|install) + (if|info|se|search|in|install)
+ types=( pattern srcpackage package patch ) + types=( pattern srcpackage package patch )
+ _describe -t types 'Package types' types && return + _describe -t types 'Package types' types && return
+ ;; + ;;
+ esac + esac
+ ;; + ;;
+ esac + esac
+ +
+ # all options available for the active main command + # all options available for the active main command
_describe -t zypper-commands 'zypper command' cmdlist _describe -t zypper-commands 'zypper command' cmdlist
+ +
+ case $cmd in + case $cmd in
+ (lr|repos) + (lr|repos)
+ _all_repos + _all_repos
+ ;; + ;;
+ (in|install) + (in|install)
+ local expl + local expl
+ _description files expl 'RPM files' + _description files expl 'RPM files'
+ _files "$expl[@]" -g '*.(#i)rpm(.)' + _files "$expl[@]" -g '*.(#i)rpm(.)'
+ ;; + ;;
+ esac + esac
+ +
+ # only suggest packages if at least one character is given + # only suggest packages if at least one character is given
@ -135,26 +187,26 @@ Index: zsh-5.0.4/Completion/openSUSE/Command/_zypper
+ +
+ if ( [[ ${+_zypp_all_raw} -eq 0 ]] || _cache_invalid ZYPPER_ALL_RAW ) && ! _retrieve_cache ZYPPER_ALL_RAW; + if ( [[ ${+_zypp_all_raw} -eq 0 ]] || _cache_invalid ZYPPER_ALL_RAW ) && ! _retrieve_cache ZYPPER_ALL_RAW;
+ then + then
+ _zypp_all_raw=$(zypper -x -q se | grep '<solvable ') + _zypp_all_raw=$(zypper -x -q se | grep '<solvable' | cut -d \" -f 2,4)
+ _zypp_all=( $(echo $_zypp_all_raw | grep 'installed' | cut -d\" -f 4) ) + _zypp_all=( $(echo $_zypp_all_raw | grep 'installed' | cut -d\" -f 2) )
+ _zypp_not_installed=( $(echo $_zypp_all_raw | grep 'not-installed' | cut -d\" -f 4 ) ) + _zypp_not_installed=( $(echo $_zypp_all_raw | grep 'not-installed' | cut -d\" -f 2 ) )
+ _zypp_installed=( $(echo $_zypp_all_raw | grep '"installed"' | cut -d\" -f 4 ) ) + _zypp_installed=( $(echo $_zypp_all_raw | grep '^installed' | cut -d\" -f 2 ) )
+ _store_cache ZYPPER_ALL_RAW _zypp_all_raw _zypp_all _zypp_not_installed _zypp_installed + _store_cache ZYPPER_ALL_RAW _zypp_all_raw _zypp_all _zypp_not_installed _zypp_installed
+ fi + fi
+ +
+ case $cmd in + case $cmd in
+ (in|install) + (in|install)
+ pkglist=( $_zypp_not_installed ) + pkglist=( $_zypp_not_installed )
+ compadd $pkglist && return + compadd $pkglist && return
+ ;; + ;;
+ (rm|remove|up|update) + (rm|remove|up|update)
+ pkglist=( $_zypp_installed ) + pkglist=( $_zypp_installed )
+ compadd $pkglist && return + compadd $pkglist && return
+ ;; + ;;
+ (if|info|se|search) + (if|info|se|search)
+ pkglist=( $_zypp_all ) + pkglist=( $_zypp_all )
+ compadd $pkglist && return + compadd $pkglist && return
+ ;; + ;;
+ esac + esac
+ fi + fi
else else

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Fri Jan 17 09:42:03 UTC 2014 - idonmez@suse.com
- Update zsh-update-zypper-completion.patch to v0.3
------------------------------------------------------------------- -------------------------------------------------------------------
Thu Jan 16 09:44:48 UTC 2014 - idonmez@suse.com Thu Jan 16 09:44:48 UTC 2014 - idonmez@suse.com