* PATCH Completion for _yum (contains FIXMEs)
@ 2016-10-26 17:37 Paul Seyfert
2016-10-27 1:30 ` Daniel Shahaf
0 siblings, 1 reply; 19+ messages in thread
From: Paul Seyfert @ 2016-10-26 17:37 UTC (permalink / raw)
To: zsh workers
[-- Attachment #1: Type: text/plain, Size: 1640 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Hi,
as posted [here][1] I'm attaching my patch for the completion of yum.
In two versions: once just the changes I did, and then the outcome of
autoindenting (the original file was anyhow mixed in tabs and spaces so
i didn't bother to reproduce the indentation style)
There are two fixmes for which I'd need suggestions. Some of the yum
history commands take IDs of past transactions. Single IDs or ID ranges,
e.g.
yum history list 3..16
where IDs range from 1 to
`yum history stats | grep Transactions | sed "s/.*: //"`
At the moment, there are just '1' '2' '3' '1..2' '1..3' '2..3' hard
coded as place holders. I don't know what's a sensible way to provide
a completion for these.
Thanks for consideration,
Paul
[1] : https://github.com/zsh-users/zsh/pull/10
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJYEOnRAAoJEPOmP9OjPXmr7XcQAJw18rPLyIXa1Td4yxmEn4Gs
8ZBARDJlETSaLsmgv24CX6Q7BkTacBWD1UGLkC3r5H4x60z07fhMjrkD5h92DtO8
sueg5rvLlGBGzj7VMaP4jpAFl//qxFhTZPO2+RWEiRFadkkb2H7V+9cJdO8t85nN
wSrOCduB7MyBRdicA97q5p9/FSaDa7RocMKAlpvYV6Y2fYm3NVg3i8dectswItap
ys00668PfaCdaLurn0+mqJDDAj43IyoOaGjo29dZ8lv/h5Gn/EG74+fRsdtCtroW
qLBKT5Xx4t90PuUia8D7CWLSBwdM3oFzeRLd+Y2BMpWtzuNiwBqG3UkfM8CRrZz5
/UhEGEX6YbxMBhRo1a82f2KA85lylahRVo411SXaXWDnTaQLUy+iS+Y+vmgkds/2
wfVQue7PtfK+DTdGuALP/0YgEkUJjniOkhuBGMZ0Ebg3dE0xMBAYr/mHEy3E37NT
SY5WKqQszkNDVV3h4zYU8G+3vHm3JcXCHhirMBhADxsIBztM+M9c3TTPAV0YYf+e
wxZbaZBu8hdQ4ugtZIwT4fuZmLv1VuVd/T4gxXhbW9jSk0e4n7qYcKLtqsMRb5HS
kuYYXIvTBd5VdlM0KBGPNUGfQBwXljkAU6BZYBmWDylhho9U9VNLXcea8UNNR9pc
MtidaBwmZ5Z811gJ/Yuy
=eLut
-----END PGP SIGNATURE-----
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: extend-yum-completion.patch --]
[-- Type: text/x-patch; name="extend-yum-completion.patch", Size: 21847 bytes --]
From d6d425f5469299d7ae7ae6c33769868eb0b0e87e Mon Sep 17 00:00:00 2001
From: Paul Seyfert <paul.seyfert@mib.infn.it>
Date: Sun, 23 Oct 2016 01:42:46 +0200
Subject: [PATCH] extend yum completion
Follwing the man page of yum 3.2.29
* update-to (just what update expands)
* upgrade-to (just what update expands)
* history (the actual tricky one)
* help (printing the available commands)
* load-transaction (_files)
* load-ts (_files)
* check (just what the man page suggested)
* reinstall (just what erase does - suggest installed packages)
* downgrade (just what erase does - suggest installed packages)
* repolist (just what the man page suggested)
* distribution-synchronization (just what erase does - suggest installed packages)
* distro-sync (just what erase does - suggest installed packages)
auto indented entire file
---
Completion/Redhat/Command/_yum | 508 ++++++++++++++++++++++++++---------------
1 file changed, 320 insertions(+), 188 deletions(-)
diff --git a/Completion/Redhat/Command/_yum b/Completion/Redhat/Command/_yum
index f453806..537b0da 100644
--- a/Completion/Redhat/Command/_yum
+++ b/Completion/Redhat/Command/_yum
@@ -3,293 +3,425 @@
# Main dispatcher
_yum()
{
- local curcontext="$curcontext" state lstate line
-
- _arguments -s \
- '(- *)'{-h,--help}'[show the help message]' \
- '(-t --tolerant)'{-t,--tolerant}'[be tolerant of errors]' \
- '(-C --cacheonly)'{-C,--cacheonly}'[run entirely from cache]' \
- '(-c --config)'{-c,--config=}'[config file location]:Yum conf file:_files' \
- '(-R --randomwait)'{-R,--randomwait=}'[maximum command wait time (in minutes)]:max wait time' \
- '(-d --debuglevel)'{-d,--debuglevel=}'[debug level (0-10)]:debug level' \
- '(-e --errorlevel)'{-e,--errorlevel=}'[error level (0-10)]:error level' \
- '(-y --assumeyes)'{-y,--assumeyes}'[answer yes for all questions]' \
- '--installroot=[set install root]:install root:_files -/' \
- '*--enablerepo=[enable or or more repositories]:repos to enable:_yum_disabled_repos_list' \
- '*--disablerepo=[disable one or more repositories]:disable repos:_yum_enabled_repos_list' \
- {*-x,*--exclude=}'[exclude package(s) by name or glob]:exclude packages' \
- '--version[show yum version]' \
- '--obsoletes[enable obsoletes processing during updates]' \
- '--nogpgcheck[disable gpg signature checking]' \
- '--noplugins[disable yum plugins]' \
- '--disablepresto[disable Presto plugin and don''''t download any deltarpms]' \
- '*::yum command:_yum_command'
+ local curcontext="$curcontext" state lstate line
+
+ _arguments -s \
+ '(- *)'{-h,--help}'[show the help message]' \
+ '(-t --tolerant)'{-t,--tolerant}'[be tolerant of errors]' \
+ '(-C --cacheonly)'{-C,--cacheonly}'[run entirely from cache]' \
+ '(-c --config)'{-c,--config=}'[config file location]:Yum conf file:_files' \
+ '(-R --randomwait)'{-R,--randomwait=}'[maximum command wait time (in minutes)]:max wait time' \
+ '(-d --debuglevel)'{-d,--debuglevel=}'[debug level (0-10)]:debug level' \
+ '(-e --errorlevel)'{-e,--errorlevel=}'[error level (0-10)]:error level' \
+ '(-y --assumeyes)'{-y,--assumeyes}'[answer yes for all questions]' \
+ '--installroot=[set install root]:install root:_files -/' \
+ '*--enablerepo=[enable or or more repositories]:repos to enable:_yum_disabled_repos_list' \
+ '*--disablerepo=[disable one or more repositories]:disable repos:_yum_enabled_repos_list' \
+ {*-x,*--exclude=}'[exclude package(s) by name or glob]:exclude packages' \
+ '--version[show yum version]' \
+ '--obsoletes[enable obsoletes processing during updates]' \
+ '--nogpgcheck[disable gpg signature checking]' \
+ '--noplugins[disable yum plugins]' \
+ '--disablepresto[disable Presto plugin and don''''t download any deltarpms]' \
+ '*::yum command:_yum_command'
}
(( $+functions[_yum_command] )) || _yum_command()
{
- local -a _yum_cmds
- _yum_cmds=(
- "install:install the latest version of a package or group of packages"
- "erase:remove an installed package (with its dependencies)"
- "remove:remove an installed package (with its dependencies)"
- "clean:clean local yum cache"
- "deplist:gives a list of all dependencies for a package"
- "check-update:check if any updates are available"
- "info:get description of available packages"
- "list:is used to list various information about packages"
- "groupinfo:get info on package groups"
- "groupinstall:install a package group or groups"
- "groupremove:remove a package group or groups"
- "grouplist:list package groups"
- "groupupdate:update a package group or groups"
- "localinstall:install packages with local rpm files"
- "localupdate:update packages with local rpm files"
- "makecache:makes a local yum cache"
- "provides:find out which package provides some feature or file"
- "whatprovides:find out which package provides some feature or file"
- "resolvedep:list packages providing the specified dependencies"
- "search:find any packages matching pattern"
- "shell:enter the 'yum shell'"
- "update:update one or more packages"
- "upgrade:upgrade one or more packages"
- )
-
- if (( CURRENT == 1 )); then
- _describe -t commands 'yum command' _yum_cmds || compadd "$@"
- else
- local curcontext="$curcontext"
-
- cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
- # Deal with any aliases
- case $cmd in
- remove) cmd="erase";;
- whatprovides) cmd="provides";;
- upgrade) cmd="update";;
- esac
-
- if (( $#cmd )); then
- curcontext="${curcontext%:*:*}:yum-${cmd}:"
-
- local update_policy
- zstyle -s ":completion:${curcontext}:" cache-policy update_policy
- if [[ -z "$update_policy" ]]; then
- zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
- fi
-
- _call_function ret _yum_$cmd || _message 'no more arguments'
- else
- _message "unknown yum command: $words[1]"
- fi
- return ret
- fi
+ local -a _yum_cmds
+ _yum_cmds=(
+ "install:install the latest version of a package or group of packages"
+ "erase:remove an installed package (with its dependencies)"
+ "remove:remove an installed package (with its dependencies)"
+ "clean:clean local yum cache"
+ "deplist:gives a list of all dependencies for a package"
+ "check-update:check if any updates are available"
+ "info:get description of available packages"
+ "list:is used to list various information about packages"
+ "groupinfo:get info on package groups"
+ "groupinstall:install a package group or groups"
+ "groupremove:remove a package group or groups"
+ "grouplist:list package groups"
+ "groupupdate:update a package group or groups"
+ "localinstall:install packages with local rpm files"
+ "localupdate:update packages with local rpm files"
+ "makecache:makes a local yum cache"
+ "provides:find out which package provides some feature or file"
+ "whatprovides:find out which package provides some feature or file"
+ "resolvedep:list packages providing the specified dependencies"
+ "search:find any packages matching pattern"
+ "shell:enter the 'yum shell'"
+ "update:update one or more packages"
+ "upgrade:upgrade one or more packages"
+ "update-to:update one or more packages taking obsoletes into account"
+ "upgrade-to:upgrade one or more packages taking obsoletes into account"
+ "history:view past transactions"
+ "help:produce help for all or given command"
+ "load-transaction:load a saved transaction from a textfile"
+ "load-ts:load a saved transaction from a textfile"
+ "check:Check for problems in the rpmdb"
+ "reinstall:reinstall a package"
+ "downgrade:downgrade a package"
+ "repolist:Display the configured software repositories"
+ "distribution-synchronization:Synchronize installed packages to the latest available versions"
+ "distro-sync:Synchronize installed packages to the latest available versions"
+ )
+
+ if (( CURRENT == 1 )); then
+ _describe -t commands 'yum command' _yum_cmds || compadd "$@"
+ else
+ local curcontext="$curcontext"
+
+ cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
+ # Deal with any aliases
+ case $cmd in
+ remove) cmd="erase";;
+ whatprovides) cmd="provides";;
+ upgrade) cmd="update";;
+ upgrade-to) cmd="update";;
+ update-to) cmd="update";;
+ load-ts) cmd="load-transaction";;
+ distro-sync) cmd="distribution-synchronization";;
+ esac
+
+ if (( $#cmd )); then
+ curcontext="${curcontext%:*:*}:yum-${cmd}:"
+
+ local update_policy
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
+ fi
+
+ if [ "$cmd" = "help" ]; then
+ if (( CURRENT == 2 )); then
+ local -a _yum_cmd_names
+ _yum_cmd_names=(${_yum_cmds%%:*})
+ _describe -t commands 'commands' _yum_cmd_names
+ else
+ _message 'no more arguments'
+ fi
+ else
+ _call_function ret _yum_$cmd || _message 'no more arguments'
+ fi
+ else
+ _message "unknown yum command: $words[1]"
+ fi
+ return ret
+ fi
+}
+
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ local -a chkargs
+ #chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ #chkargs=("dependencies" "duplicates" "all") # according to help
+ chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ _describe -t arguments 'check arguments' chkargs
+ fi
+ return 0
}
+# Expand next argument after 'yum repolist'
+_yum_repolist() {
+ if (( CURRENT == 2 )); then
+ local -a suggests
+ suggests=("all" "enabled" "disabled")
+ _describe -t arguments 'repolist arguments' suggests
+ fi
+ return 0
+}
+
+# Expand next argument after 'yum history'
+_yum_history() {
+ if (( CURRENT == 2 )); then
+ local -a historycommands
+ historycommands=('info' 'list' 'packages-list' 'packages-info' 'summary' 'addon-info' 'redo' 'undo' 'roll-back' 'new' 'sync' 'stats')
+ _describe -t commands 'yum history command' historycommands
+ fi
+ if (( CURRENT == 3 )); then
+ local -a ID_commands
+ local -a ID_range_commands
+ local -a package_commands
+ local -a suggests
+ local description
+ description=""
+ suggests=()
+ ID_commands=('summary' 'info' 'list' 'stats' 'addon-info')
+ ID_range_commands=('summary' 'info' 'list' 'stats')
+ package_commands=('summary' 'info' 'list' 'stats' 'packages-list' 'packages-info')
+ # packages-list, packages-info : needs package name
+ # summary, info, list, stats : ID, ID range, package name
+ # addon-info : ID
+ # redo, undo, roll-back, sync : unknown
+ if [[ -n "${ID_commands[(r)$words[2]]}" ]]; then
+ description+="IDs"
+ # FIXME: hard coded IDs just a draft
+ suggests+=('last' 'all' 1 2 3)
+ fi
+ if [[ -n "${ID_range_commands[(r)$words[2]]}" ]]; then
+ if [[ -n $description ]] ; then description+=", "; fi
+ description+="ID ranges"
+ # FIXME: hard coded IDs just a draft
+ suggests+=('1..2' '2..3' '1..3')
+ fi
+ if [[ -n "${package_commands[(r)$words[2]]}" ]]; then
+ if [[ -n $description ]] ; then description+=", "; fi
+ description+="packages"
+ _yum_installed_pkgs
+ suggests+=($_installed_pkgs)
+ fi
+ if [[ ! -n $description ]] ; then
+ _message "unknown expansion for: yum history $words[2]"
+ else
+ _describe $description suggests
+ fi
+ fi
+ if (( CURRENT == 4 )); then
+ if [ "$words[2]" = "addon-info" ]; then
+ local -a historyargs
+ historyargs=(saved_tx)
+ _describe 'additional option' historyargs
+ fi
+ fi
+}
+
+
# Fills the all pkg cache
_yum_all_pkgs()
{
- if ( [[ ${+_all_pkgs} -eq 0 ]] || _cache_invalid ALL ) &&
- ! _retrieve_cache ALL;
- then
- _all_pkgs=( $(yum -C list all | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache ALL _all_pkgs
- fi
+ if ( [[ ${+_all_pkgs} -eq 0 ]] || _cache_invalid ALL ) &&
+ ! _retrieve_cache ALL;
+then
+ _all_pkgs=( $(yum -C list all | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache ALL _all_pkgs
+fi
}
# Fills the installed pkg cache
_yum_installed_pkgs()
{
- if ( [[ ${+_installed_pkgs} -eq 0 ]] || _cache_invalid INSTALLED ) &&
- ! _retrieve_cache INSTALLED;
- then
- _installed_pkgs=( $(yum -C list installed | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache INSTALLED _installed_pkgs
- fi
+ if ( [[ ${+_installed_pkgs} -eq 0 ]] || _cache_invalid INSTALLED ) &&
+ ! _retrieve_cache INSTALLED;
+then
+ _installed_pkgs=( $(yum -C list installed | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache INSTALLED _installed_pkgs
+fi
}
# Fills the available pkg cache
_yum_available_pkgs()
{
- if ( [[ ${+_available_pkgs} -eq 0 ]] || _cache_invalid AVAILABLE ) &&
- ! _retrieve_cache AVAILABLE;
- then
- _available_pkgs=( $(yum -C list available | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache AVAILABLE _available_pkgs
- fi
+ if ( [[ ${+_available_pkgs} -eq 0 ]] || _cache_invalid AVAILABLE ) &&
+ ! _retrieve_cache AVAILABLE;
+then
+ _available_pkgs=( $(yum -C list available | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache AVAILABLE _available_pkgs
+fi
}
# Fills the upgrade pkg cache
_yum_upgrade_pkgs()
{
- if ( [[ ${+_upgrade_pkgs} -eq 0 ]] || _cache_invalid UPGRADE ) &&
- ! _retrieve_cache UPGRADE;
- then
- _upgrade_pkgs=( $(yum -C list upgrade | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache UPGRADE _upgrade_pkgs
- fi
+ if ( [[ ${+_upgrade_pkgs} -eq 0 ]] || _cache_invalid UPGRADE ) &&
+ ! _retrieve_cache UPGRADE;
+then
+ _upgrade_pkgs=( $(yum -C list upgrade | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache UPGRADE _upgrade_pkgs
+fi
}
# Gets the list of defined repos
yum_repos() {
- local trepo
- local -a tarray
- tarray=( $(egrep -h '(^\[.*\]|^enabled.*=)' /etc/yum.repos.d/*.repo /etc/yum.conf | sed -e 's/ //g' | sed -e 's/\[//g' | sed -e 's/\].*$//g' 2>/dev/null) )
- local -i eindex=0
- local -i dindex=0
- for line in $tarray; do
- if [[ "$line" = "enabled=1" ]]; then
- enabled_yum_repos=($enabled_yum_repos $trepo)
- elif [[ "$line" = "enabled=0" ]]; then
- disabled_yum_repos=($disabled_yum_repos $trepo)
- elif [[ "$line" != "main" ]]; then
- trepo=$line
- fi
- done
+ local trepo
+ local -a tarray
+ tarray=( $(egrep -h '(^\[.*\]|^enabled.*=)' /etc/yum.repos.d/*.repo /etc/yum.conf | sed -e 's/ //g' | sed -e 's/\[//g' | sed -e 's/\].*$//g' 2>/dev/null) )
+ local -i eindex=0
+ local -i dindex=0
+ for line in $tarray; do
+ if [[ "$line" = "enabled=1" ]]; then
+ enabled_yum_repos=($enabled_yum_repos $trepo)
+ elif [[ "$line" = "enabled=0" ]]; then
+ disabled_yum_repos=($disabled_yum_repos $trepo)
+ elif [[ "$line" != "main" ]]; then
+ trepo=$line
+ fi
+ done
}
(( $+functions[_yum_disabled_repos_list] )) || _yum_disabled_repos_list()
{
- compset -P '*,'
- compset -S ',*'
- yum_repos
- compadd "$@" -a -- disabled_yum_repos
+ compset -P '*,'
+ compset -S ',*'
+ yum_repos
+ compadd "$@" -a -- disabled_yum_repos
}
(( $+functions[_yum_enabled_repos_list] )) || _yum_enabled_repos_list()
{
- compset -P '*,'
- compset -S ',*'
- yum_repos
- compadd "$@" -a -- enabled_yum_repos
+ compset -P '*,'
+ compset -S ',*'
+ yum_repos
+ compadd "$@" -a -- enabled_yum_repos
+}
+
+# Suggest installed packages
+_yum_act_on_installed_pkgs() {
+ _yum_installed_pkgs
+ compadd "$@" -a -- _installed_pkgs
+}
+
+# Completion function for distribution-synchronization|distro-sync
+(( $+functions[_yum_distribution-synchronization] )) || _yum_distribution-synchronization()
+{
+ _yum_act_on_installed_pkgs
}
# Completion function for erase|remove
(( $+functions[_yum_erase] )) || _yum_erase()
{
- _yum_installed_pkgs
- compadd "$@" -a -- _installed_pkgs
+ _yum_act_on_installed_pkgs
+}
+
+# Completion function for downgrade
+(( $+functions[_yum_downgrade] )) || _yum_downgrade()
+{
+ _yum_act_on_installed_pkgs
+}
+
+# Completion function for reinstall
+(( $+functions[_yum_reinstall] )) || _yum_reinstall()
+{
+ _yum_act_on_installed_pkgs
}
# Completion function for install
(( $+functions[_yum_install] )) || _yum_install()
{
- if ! [[ $PREFIX == */* ]]; then
- _yum_available_pkgs
- fi
+ if ! [[ $PREFIX == */* ]]; then
+ _yum_available_pkgs
+ fi
+
+ local ret=1
+ _tags files packages
+ while _tags; do
+ if _requested files; then
+ compadd "$@" -a -- _available_pkgs
+ fi
+ if _requested packages; then
+ _call_function - _yum_localinstall
+ fi
+ (( ret )) || break
+ done
+ return ret
+}
- local ret=1
- _tags files packages
- while _tags; do
- if _requested files; then
- compadd "$@" -a -- _available_pkgs
- fi
- if _requested packages; then
- _call_function - _yum_localinstall
- fi
- (( ret )) || break
- done
- return ret
+# Completion function for load-transaction
+(( $+functions[_yum_load-transaction] )) || _yum_load-transaction()
+{
+ _files
}
# Completion function for localinstall
(( $+functions[_yum_localinstall] )) || _yum_localinstall()
{
- _files -/ -g '(#i)*.rpm(-.)'
+ _files -/ -g '(#i)*.rpm(-.)'
}
# Completion function for localupdate
(( $+functions[_yum_localupdate] )) || _yum_localupdate()
{
- _files -/ -g '(#i)*.rpm(-.)'
+ _files -/ -g '(#i)*.rpm(-.)'
}
# Completion function for update/upgrade
(( $+functions[_yum_update] )) || _yum_update()
{
- _yum_upgrade_pkgs
- compadd "$@" -a -- _upgrade_pkgs
+ _yum_upgrade_pkgs
+ compadd "$@" -a -- _upgrade_pkgs
}
# Completion function for deplist
(( $+functions[_yum_deplist] )) || _yum_deplist()
{
- _yum_available_pkgs
- compadd "$@" -a -- _available_pkgs
+ _yum_available_pkgs
+ compadd "$@" -a -- _available_pkgs
}
_yum_all()
{
- _yum_all_pkgs
- compadd "$@" -a -- _all_pkgs
+ _yum_all_pkgs
+ compadd "$@" -a -- _all_pkgs
}
_yum_list_or_info()
{
- local -a listlist
- listlist=(
- "all:all packages in repositories"
- "available:packages available in repositories"
- "updates:packages with updates available"
- "installed:installed packages"
- "extras:packages installed that are not available in any yum repository"
- "obsoletes:packages installed that are obsoleted"
- "recent:packages recently added to repositories"
- )
-
- if (( CURRENT == 2 )); then
- _describe -t yum-list-subcmds "Yum info/list sub-commands" listlist || _yum_all
- else
- local subcmd
- subcmd="${${listlist[(r)$words[2]:*]%%:*}}"
- # offer packages selected by the subcommand
- case $subcmd in
- all) _yum_all;;
- installed) _yum_erase;;
- available) _yum_install;;
- updates) _yum_update;;
- esac
- fi
+ local -a listlist
+ listlist=(
+ "all:all packages in repositories"
+ "available:packages available in repositories"
+ "updates:packages with updates available"
+ "installed:installed packages"
+ "extras:packages installed that are not available in any yum repository"
+ "obsoletes:packages installed that are obsoleted"
+ "recent:packages recently added to repositories"
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t yum-list-subcmds "Yum info/list sub-commands" listlist || _yum_all
+ else
+ local subcmd
+ subcmd="${${listlist[(r)$words[2]:*]%%:*}}"
+ # offer packages selected by the subcommand
+ case $subcmd in
+ all) _yum_all;;
+ installed) _yum_erase;;
+ available) _yum_install;;
+ updates) _yum_update;;
+ esac
+ fi
}
# Completion function for list
(( $+functions[_yum_list] )) || _yum_list()
{
- _yum_list_or_info
+ _yum_list_or_info
}
# Completion function for info
(( $+functions[_yum_info] )) || _yum_info()
{
- _yum_list_or_info
+ _yum_list_or_info
}
# Completion function for provides|whatprovides
(( $+functions[_yum_provides] )) || _yum_provides()
{
- _files
+ _files
}
# Completion function for resolvedep
(( $+functions[_yum_resolvedep] )) || _yum_resolvedep()
{
- _files
+ _files
}
# Completion function for clean
(( $+functions[_yum_clean] )) || _yum_clean()
{
- local -a cleanlist
- cleanlist=(
- "all:all cache"
- "cache:all cache"
- "dbcache:DB cache"
- "headers:cache headers"
- "packages:cache packages"
- "metadata:cache meta-data"
- )
-
- if (( CURRENT == 2 )); then
- _describe -t yum-clean-subcmds "Yum clean sub-commands" cleanlist
- fi
+ local -a cleanlist
+ cleanlist=(
+ "all:all cache"
+ "cache:all cache"
+ "dbcache:DB cache"
+ "headers:cache headers"
+ "packages:cache packages"
+ "metadata:cache meta-data"
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t yum-clean-subcmds "Yum clean sub-commands" cleanlist
+ fi
}
_yum_caching_policy()
--
2.1.4
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: just_changes.patch --]
[-- Type: text/x-patch; name="just_changes.patch", Size: 10058 bytes --]
From 72f9dd44c4856caf9b1c60e7df732d19ebe0c3b0 Mon Sep 17 00:00:00 2001
From: Paul Seyfert <paul.seyfert@mib.infn.it>
Date: Sun, 23 Oct 2016 01:42:46 +0200
Subject: [PATCH] extend yum completion
---
Completion/Redhat/Command/_yum | 246 +++++++++++++++++++++++++++++++----------
1 file changed, 189 insertions(+), 57 deletions(-)
diff --git a/Completion/Redhat/Command/_yum b/Completion/Redhat/Command/_yum
index f453806..139bcbd 100644
--- a/Completion/Redhat/Command/_yum
+++ b/Completion/Redhat/Command/_yum
@@ -28,63 +28,166 @@ _yum()
(( $+functions[_yum_command] )) || _yum_command()
{
- local -a _yum_cmds
- _yum_cmds=(
- "install:install the latest version of a package or group of packages"
- "erase:remove an installed package (with its dependencies)"
- "remove:remove an installed package (with its dependencies)"
- "clean:clean local yum cache"
- "deplist:gives a list of all dependencies for a package"
- "check-update:check if any updates are available"
- "info:get description of available packages"
- "list:is used to list various information about packages"
- "groupinfo:get info on package groups"
- "groupinstall:install a package group or groups"
- "groupremove:remove a package group or groups"
- "grouplist:list package groups"
- "groupupdate:update a package group or groups"
- "localinstall:install packages with local rpm files"
- "localupdate:update packages with local rpm files"
- "makecache:makes a local yum cache"
- "provides:find out which package provides some feature or file"
- "whatprovides:find out which package provides some feature or file"
- "resolvedep:list packages providing the specified dependencies"
- "search:find any packages matching pattern"
- "shell:enter the 'yum shell'"
- "update:update one or more packages"
- "upgrade:upgrade one or more packages"
- )
-
- if (( CURRENT == 1 )); then
- _describe -t commands 'yum command' _yum_cmds || compadd "$@"
- else
- local curcontext="$curcontext"
-
- cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
- # Deal with any aliases
- case $cmd in
- remove) cmd="erase";;
- whatprovides) cmd="provides";;
- upgrade) cmd="update";;
- esac
-
- if (( $#cmd )); then
- curcontext="${curcontext%:*:*}:yum-${cmd}:"
-
- local update_policy
- zstyle -s ":completion:${curcontext}:" cache-policy update_policy
- if [[ -z "$update_policy" ]]; then
- zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
- fi
-
- _call_function ret _yum_$cmd || _message 'no more arguments'
- else
- _message "unknown yum command: $words[1]"
- fi
- return ret
- fi
+ local -a _yum_cmds
+ _yum_cmds=(
+ "install:install the latest version of a package or group of packages"
+ "erase:remove an installed package (with its dependencies)"
+ "remove:remove an installed package (with its dependencies)"
+ "clean:clean local yum cache"
+ "deplist:gives a list of all dependencies for a package"
+ "check-update:check if any updates are available"
+ "info:get description of available packages"
+ "list:is used to list various information about packages"
+ "groupinfo:get info on package groups"
+ "groupinstall:install a package group or groups"
+ "groupremove:remove a package group or groups"
+ "grouplist:list package groups"
+ "groupupdate:update a package group or groups"
+ "localinstall:install packages with local rpm files"
+ "localupdate:update packages with local rpm files"
+ "makecache:makes a local yum cache"
+ "provides:find out which package provides some feature or file"
+ "whatprovides:find out which package provides some feature or file"
+ "resolvedep:list packages providing the specified dependencies"
+ "search:find any packages matching pattern"
+ "shell:enter the 'yum shell'"
+ "update:update one or more packages"
+ "upgrade:upgrade one or more packages"
+ "update-to:update one or more packages taking obsoletes into account"
+ "upgrade-to:upgrade one or more packages taking obsoletes into account"
+ "history:view past transactions"
+ "help:produce help for all or given command"
+ "load-transaction:load a saved transaction from a textfile"
+ "load-ts:load a saved transaction from a textfile"
+ "check:Check for problems in the rpmdb"
+ "reinstall:reinstall a package"
+ "downgrade:downgrade a package"
+ "repolist:Display the configured software repositories"
+ "distribution-synchronization:Synchronize installed packages to the latest available versions"
+ "distro-sync:Synchronize installed packages to the latest available versions"
+ )
+
+ if (( CURRENT == 1 )); then
+ _describe -t commands 'yum command' _yum_cmds || compadd "$@"
+ else
+ local curcontext="$curcontext"
+
+ cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
+ # Deal with any aliases
+ case $cmd in
+ remove) cmd="erase";;
+ whatprovides) cmd="provides";;
+ upgrade) cmd="update";;
+ upgrade-to) cmd="update";;
+ update-to) cmd="update";;
+ load-ts) cmd="load-transaction";;
+ distro-sync) cmd="distribution-synchronization";;
+ esac
+
+ if (( $#cmd )); then
+ curcontext="${curcontext%:*:*}:yum-${cmd}:"
+
+ local update_policy
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
+ fi
+
+ if [ "$cmd" = "help" ]; then
+ if (( CURRENT == 2 )); then
+ local -a _yum_cmd_names
+ _yum_cmd_names=(${_yum_cmds%%:*})
+ _describe -t commands 'commands' _yum_cmd_names
+ else
+ _message 'no more arguments'
+ fi
+ else
+ _call_function ret _yum_$cmd || _message 'no more arguments'
+ fi
+ else
+ _message "unknown yum command: $words[1]"
+ fi
+ return ret
+ fi
}
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ local -a chkargs
+ #chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ #chkargs=("dependencies" "duplicates" "all") # according to help
+ chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ _describe -t arguments 'check arguments' chkargs
+ fi
+ return 0
+}
+
+# Expand next argument after 'yum repolist'
+_yum_repolist() {
+ if (( CURRENT == 2 )); then
+ local -a suggests
+ suggests=("all" "enabled" "disabled")
+ _describe -t arguments 'repolist arguments' suggests
+ fi
+ return 0
+}
+
+# Expand next argument after 'yum history'
+_yum_history() {
+ if (( CURRENT == 2 )); then
+ local -a historycommands
+ historycommands=('info' 'list' 'packages-list' 'packages-info' 'summary' 'addon-info' 'redo' 'undo' 'roll-back' 'new' 'sync' 'stats')
+ _describe -t commands 'yum history command' historycommands
+ fi
+ if (( CURRENT == 3 )); then
+ local -a ID_commands
+ local -a ID_range_commands
+ local -a package_commands
+ local -a suggests
+ local description
+ description=""
+ suggests=()
+ ID_commands=('summary' 'info' 'list' 'stats' 'addon-info')
+ ID_range_commands=('summary' 'info' 'list' 'stats')
+ package_commands=('summary' 'info' 'list' 'stats' 'packages-list' 'packages-info')
+ # packages-list, packages-info : needs package name
+ # summary, info, list, stats : ID, ID range, package name
+ # addon-info : ID
+ # redo, undo, roll-back, sync : unknown
+ if [[ -n "${ID_commands[(r)$words[2]]}" ]]; then
+ description+="IDs"
+ # FIXME: hard coded IDs just a draft
+ suggests+=('last' 'all' 1 2 3)
+ fi
+ if [[ -n "${ID_range_commands[(r)$words[2]]}" ]]; then
+ if [[ -n $description ]] ; then description+=", "; fi
+ description+="ID ranges"
+ # FIXME: hard coded IDs just a draft
+ suggests+=('1..2' '2..3' '1..3')
+ fi
+ if [[ -n "${package_commands[(r)$words[2]]}" ]]; then
+ if [[ -n $description ]] ; then description+=", "; fi
+ description+="packages"
+ _yum_installed_pkgs
+ suggests+=($_installed_pkgs)
+ fi
+ if [[ ! -n $description ]] ; then
+ _message "unknown expansion for: yum history $words[2]"
+ else
+ _describe $description suggests
+ fi
+ fi
+ if (( CURRENT == 4 )); then
+ if [ "$words[2]" = "addon-info" ]; then
+ local -a historyargs
+ historyargs=(saved_tx)
+ _describe 'additional option' historyargs
+ fi
+ fi
+}
+
+
# Fills the all pkg cache
_yum_all_pkgs()
{
@@ -163,11 +266,34 @@ yum_repos() {
compadd "$@" -a -- enabled_yum_repos
}
+# Suggest installed packages
+_yum_act_on_installed_pkgs() {
+ _yum_installed_pkgs
+ compadd "$@" -a -- _installed_pkgs
+}
+
+# Completion function for distribution-synchronization|distro-sync
+(( $+functions[_yum_distribution-synchronization] )) || _yum_distribution-synchronization()
+{
+ _yum_act_on_installed_pkgs
+}
+
# Completion function for erase|remove
(( $+functions[_yum_erase] )) || _yum_erase()
{
- _yum_installed_pkgs
- compadd "$@" -a -- _installed_pkgs
+ _yum_act_on_installed_pkgs
+}
+
+# Completion function for downgrade
+(( $+functions[_yum_downgrade] )) || _yum_downgrade()
+{
+ _yum_act_on_installed_pkgs
+}
+
+# Completion function for reinstall
+(( $+functions[_yum_reinstall] )) || _yum_reinstall()
+{
+ _yum_act_on_installed_pkgs
}
# Completion function for install
@@ -191,6 +317,12 @@ yum_repos() {
return ret
}
+# Completion function for load-transaction
+(( $+functions[_yum_load-transaction] )) || _yum_load-transaction()
+{
+ _files
+}
+
# Completion function for localinstall
(( $+functions[_yum_localinstall] )) || _yum_localinstall()
{
--
2.1.4
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: PATCH Completion for _yum (contains FIXMEs)
2016-10-26 17:37 PATCH Completion for _yum (contains FIXMEs) Paul Seyfert
@ 2016-10-27 1:30 ` Daniel Shahaf
2016-10-31 12:09 ` Paul Seyfert
0 siblings, 1 reply; 19+ messages in thread
From: Daniel Shahaf @ 2016-10-27 1:30 UTC (permalink / raw)
To: Paul Seyfert; +Cc: zsh workers
I've taken a look at the FIXMEs — answers below — but haven't done
a full review.
Paul Seyfert wrote on Wed, Oct 26, 2016 at 19:37:21 +0200:
> There are two fixmes for which I'd need suggestions. Some of the yum
> history commands take IDs of past transactions. Single IDs or ID ranges,
> e.g.
>
> yum history list 3..16
>
> where IDs range from 1 to
> `yum history stats | grep Transactions | sed "s/.*: //"`
>
> At the moment, there are just '1' '2' '3' '1..2' '1..3' '2..3' hard
> coded as place holders. I don't know what's a sensible way to provide
> a completion for these.
Something like this:
.
_id_ranges() { if compset -P '*..'; then _ids; else _ids -S ..; fi }
.
where _ids() is a function that adds "1" "2" "3" as completions.
There should be examples of this in the revision ranges handling in
_git/_hg/_subversion.
> + if [[ -n "${ID_commands[(r)$words[2]]}" ]]; then
> + description+="IDs"
> + # FIXME: hard coded IDs just a draft
> + suggests+=('last' 'all' 1 2 3)
> + fi
> + if [[ -n "${ID_range_commands[(r)$words[2]]}" ]]; then
> + if [[ -n $description ]] ; then description+=", "; fi
> + description+="ID ranges"
> + # FIXME: hard coded IDs just a draft
> + suggests+=('1..2' '2..3' '1..3')
> + fi
> + if [[ -n "${package_commands[(r)$words[2]]}" ]]; then
> + if [[ -n $description ]] ; then description+=", "; fi
> + description+="packages"
> + _yum_installed_pkgs
> + suggests+=($_installed_pkgs)
> + fi
> + if [[ ! -n $description ]] ; then
> + _message "unknown expansion for: yum history $words[2]"
> + else
> + _describe $description suggests
> + fi
> + fi
This looks like it would be better written with _alternative:
alts=()
[[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=( 'id-ranges:id ranges:_id-ranges' )
[[ -n "${package_commands[(r)$words[2]]}" ]] && alts+=( 'packages:packages:...' )
⋮
(( ${+alts[1]} )) && _alternative "$alts[@]"
To see the difference, set the «group-name» style to «''» (and
optionally the «format» style to something with «%d» in it). You can
see this in «ssh <TAB>» too (compare with/without those two styles).
Let's see what the other devs have to say about the rest of the patch.
Cheers,
Daniel
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: PATCH Completion for _yum (contains FIXMEs)
2016-10-27 1:30 ` Daniel Shahaf
@ 2016-10-31 12:09 ` Paul Seyfert
2016-11-10 10:18 ` Paul Seyfert
0 siblings, 1 reply; 19+ messages in thread
From: Paul Seyfert @ 2016-10-31 12:09 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]
Hi,
thanks for the suggestions.
On 27.10.2016 03:30, Daniel Shahaf wrote:
> Something like this:
> .
> _id_ranges() { if compset -P '*..'; then _ids; else _ids -S ..; fi }
> .
> where _ids() is a function that adds "1" "2" "3" as completions.
>
> There should be examples of this in the revision ranges handling in
> _git/_hg/_subversion.
>
added the id ranges similar to your suggestion and checking _git.
>> [snap]
>
> This looks like it would be better written with _alternative:
>
> alts=()
> [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=( 'id-ranges:id ranges:_id-ranges' )
> [[ -n "${package_commands[(r)$words[2]]}" ]] && alts+=( 'packages:packages:...' )
> ⋮
> (( ${+alts[1]} )) && _alternative "$alts[@]"
>
> To see the difference, set the «group-name» style to «''» (and
> optionally the «format» style to something with «%d» in it). You can
> see this in «ssh <TAB>» too (compare with/without those two styles).
also i'm using _alternative by now, but i'll bring it closer to your
suggestion soonish.
Cheers,
Paul
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: just_changes2.patch --]
[-- Type: text/x-patch; name="just_changes2.patch", Size: 6494 bytes --]
diff --git a/Completion/Redhat/Command/_yum b/Completion/Redhat/Command/_yum
index f453806..f9219f0 100644
--- a/Completion/Redhat/Command/_yum
+++ b/Completion/Redhat/Command/_yum
@@ -53,6 +53,18 @@ _yum()
"shell:enter the 'yum shell'"
"update:update one or more packages"
"upgrade:upgrade one or more packages"
+ "update-to:update one or more packages taking obsoletes into account"
+ "upgrade-to:upgrade one or more packages taking obsoletes into account"
+ "history:view past transactions"
+ "help:produce help for all or given command"
+ "load-transaction:load a saved transaction from a textfile"
+ "load-ts:load a saved transaction from a textfile"
+ "check:Check for problems in the rpmdb"
+ "reinstall:reinstall a package"
+ "downgrade:downgrade a package"
+ "repolist:Display the configured software repositories"
+ "distribution-synchronization:Synchronize installed packages to the latest available versions"
+ "distro-sync:Synchronize installed packages to the latest available versions"
)
if (( CURRENT == 1 )); then
@@ -66,6 +78,10 @@ _yum()
remove) cmd="erase";;
whatprovides) cmd="provides";;
upgrade) cmd="update";;
+ upgrade-to) cmd="update";;
+ update-to) cmd="update";;
+ load-ts) cmd="load-transaction";;
+ distro-sync) cmd="distribution-synchronization";;
esac
if (( $#cmd )); then
@@ -77,7 +93,17 @@ _yum()
zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
fi
+ if [ "$cmd" = "help" ]; then
+ if (( CURRENT == 2 )); then
+ local -a _yum_cmd_names
+ _yum_cmd_names=(${_yum_cmds%%:*})
+ _describe -t commands 'commands' _yum_cmd_names
+ else
+ _message 'no more arguments'
+ fi
+ else
_call_function ret _yum_$cmd || _message 'no more arguments'
+ fi
else
_message "unknown yum command: $words[1]"
fi
@@ -85,6 +111,101 @@ _yum()
fi
}
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ local -a chkargs
+ #chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ #chkargs=("dependencies" "duplicates" "all") # according to help
+ chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ _describe -t arguments 'check arguments' chkargs
+ fi
+ return 0
+}
+
+# Expand next argument after 'yum repolist'
+_yum_repolist() {
+ if (( CURRENT == 2 )); then
+ local -a suggests
+ suggests=("all" "enabled" "disabled")
+ _describe -t arguments 'repolist arguments' suggests
+ fi
+ return 0
+}
+
+_ids() {
+ # the last argument will be the first valid transaction ID to be suggested
+ # all other arguments are forwarded to compadd
+ #
+ # maxid is the last transaction ID known to yum
+ # minusone is the number of arguments provided to _ids minus one
+ local maxid
+ local minusone
+
+ maxid=$(yum history stats | grep Transactions | sed "s/.*: //")
+ ((minusone=$#-1))
+ compadd "${(@)@[1,$minusone]}" $(echo {$@[$#]..$maxid})
+}
+
+_ranges() {
+ if compset -P '*..'; then
+ _ids ${(S)IPREFIX#..}
+ else
+ _ids -S '..' 1
+ fi
+}
+
+# Expand next argument after 'yum history'
+_yum_history() {
+ if (( CURRENT == 2 )); then
+ local -a historycommands
+ historycommands=('info' 'list' 'packages-list' 'packages-info' 'summary' 'addon-info' 'redo' 'undo' 'roll-back' 'new' 'sync' 'stats')
+ _describe -t commands 'yum history command' historycommands
+ fi
+ if (( CURRENT == 3 )); then
+ local -a ID_commands
+ local -a ID_range_commands
+ local -a package_commands
+ local -a suggests
+ suggests=()
+ #ID_commands=('summary' 'info' 'list' 'stats' 'addon-info')
+ ID_commands=('addon-info')
+ ID_range_commands=('summary' 'info' 'list' 'stats')
+ package_commands=('summary' 'info' 'list' 'stats' 'packages-list' 'packages-info')
+ #package_commands=('packages-list' 'packages-info')
+ # packages-list, packages-info : needs package name
+ # summary, info, list, stats : ID, ID range, package name
+ # addon-info : ID
+ # redo, undo, roll-back, sync : unknown
+ if [[ -n "${ID_commands[(r)$words[2]]}" ]]; then
+ suggests+=(':special IDs:(last)')
+ suggests+=(':IDs:_ids 1')
+ fi
+ if [[ -n "${ID_range_commands[(r)$words[2]]}" ]]; then
+ suggests+=(':transaction ranges:_ranges')
+ suggests+=(':all transactions:(all)')
+ fi
+ if [[ -n "${package_commands[(r)$words[2]]}" ]]; then
+ _yum_installed_pkgs
+ #suggests+=(":packages:($_installed_pkgs)")
+ suggests+=(":packages:_yum_act_on_installed_pkgs")
+ fi
+ if [[ 0 -eq ${#suggests} ]] ; then
+ _message "unknown expansion for: yum history $words[2]"
+ else
+ _alternative $suggests
+ fi
+ fi
+ if (( CURRENT == 4 )); then
+ if [ "$words[2]" = "addon-info" ]; then
+ local -a historyargs
+ historyargs=(saved_tx)
+ _describe 'additional option' historyargs
+ fi
+ fi
+}
+
+
# Fills the all pkg cache
_yum_all_pkgs()
{
@@ -163,11 +284,34 @@ yum_repos() {
compadd "$@" -a -- enabled_yum_repos
}
+# Suggest installed packages
+_yum_act_on_installed_pkgs() {
+ _yum_installed_pkgs
+ compadd "$@" -a -- _installed_pkgs
+}
+
+# Completion function for distribution-synchronization|distro-sync
+(( $+functions[_yum_distribution-synchronization] )) || _yum_distribution-synchronization()
+{
+ _yum_act_on_installed_pkgs
+}
+
# Completion function for erase|remove
(( $+functions[_yum_erase] )) || _yum_erase()
{
- _yum_installed_pkgs
- compadd "$@" -a -- _installed_pkgs
+ _yum_act_on_installed_pkgs
+}
+
+# Completion function for downgrade
+(( $+functions[_yum_downgrade] )) || _yum_downgrade()
+{
+ _yum_act_on_installed_pkgs
+}
+
+# Completion function for reinstall
+(( $+functions[_yum_reinstall] )) || _yum_reinstall()
+{
+ _yum_act_on_installed_pkgs
}
# Completion function for install
@@ -191,6 +335,12 @@ yum_repos() {
return ret
}
+# Completion function for load-transaction
+(( $+functions[_yum_load-transaction] )) || _yum_load-transaction()
+{
+ _files
+}
+
# Completion function for localinstall
(( $+functions[_yum_localinstall] )) || _yum_localinstall()
{
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: extend-yum-completion2.patch --]
[-- Type: text/x-patch; name="extend-yum-completion2.patch", Size: 21226 bytes --]
diff --git a/Completion/Redhat/Command/_yum b/Completion/Redhat/Command/_yum
index f453806..4cc00cf 100644
--- a/Completion/Redhat/Command/_yum
+++ b/Completion/Redhat/Command/_yum
@@ -3,293 +3,443 @@
# Main dispatcher
_yum()
{
- local curcontext="$curcontext" state lstate line
-
- _arguments -s \
- '(- *)'{-h,--help}'[show the help message]' \
- '(-t --tolerant)'{-t,--tolerant}'[be tolerant of errors]' \
- '(-C --cacheonly)'{-C,--cacheonly}'[run entirely from cache]' \
- '(-c --config)'{-c,--config=}'[config file location]:Yum conf file:_files' \
- '(-R --randomwait)'{-R,--randomwait=}'[maximum command wait time (in minutes)]:max wait time' \
- '(-d --debuglevel)'{-d,--debuglevel=}'[debug level (0-10)]:debug level' \
- '(-e --errorlevel)'{-e,--errorlevel=}'[error level (0-10)]:error level' \
- '(-y --assumeyes)'{-y,--assumeyes}'[answer yes for all questions]' \
- '--installroot=[set install root]:install root:_files -/' \
- '*--enablerepo=[enable or or more repositories]:repos to enable:_yum_disabled_repos_list' \
- '*--disablerepo=[disable one or more repositories]:disable repos:_yum_enabled_repos_list' \
- {*-x,*--exclude=}'[exclude package(s) by name or glob]:exclude packages' \
- '--version[show yum version]' \
- '--obsoletes[enable obsoletes processing during updates]' \
- '--nogpgcheck[disable gpg signature checking]' \
- '--noplugins[disable yum plugins]' \
- '--disablepresto[disable Presto plugin and don''''t download any deltarpms]' \
- '*::yum command:_yum_command'
+ local curcontext="$curcontext" state lstate line
+
+ _arguments -s \
+ '(- *)'{-h,--help}'[show the help message]' \
+ '(-t --tolerant)'{-t,--tolerant}'[be tolerant of errors]' \
+ '(-C --cacheonly)'{-C,--cacheonly}'[run entirely from cache]' \
+ '(-c --config)'{-c,--config=}'[config file location]:Yum conf file:_files' \
+ '(-R --randomwait)'{-R,--randomwait=}'[maximum command wait time (in minutes)]:max wait time' \
+ '(-d --debuglevel)'{-d,--debuglevel=}'[debug level (0-10)]:debug level' \
+ '(-e --errorlevel)'{-e,--errorlevel=}'[error level (0-10)]:error level' \
+ '(-y --assumeyes)'{-y,--assumeyes}'[answer yes for all questions]' \
+ '--installroot=[set install root]:install root:_files -/' \
+ '*--enablerepo=[enable or or more repositories]:repos to enable:_yum_disabled_repos_list' \
+ '*--disablerepo=[disable one or more repositories]:disable repos:_yum_enabled_repos_list' \
+ {*-x,*--exclude=}'[exclude package(s) by name or glob]:exclude packages' \
+ '--version[show yum version]' \
+ '--obsoletes[enable obsoletes processing during updates]' \
+ '--nogpgcheck[disable gpg signature checking]' \
+ '--noplugins[disable yum plugins]' \
+ '--disablepresto[disable Presto plugin and don''''t download any deltarpms]' \
+ '*::yum command:_yum_command'
}
(( $+functions[_yum_command] )) || _yum_command()
{
- local -a _yum_cmds
- _yum_cmds=(
- "install:install the latest version of a package or group of packages"
- "erase:remove an installed package (with its dependencies)"
- "remove:remove an installed package (with its dependencies)"
- "clean:clean local yum cache"
- "deplist:gives a list of all dependencies for a package"
- "check-update:check if any updates are available"
- "info:get description of available packages"
- "list:is used to list various information about packages"
- "groupinfo:get info on package groups"
- "groupinstall:install a package group or groups"
- "groupremove:remove a package group or groups"
- "grouplist:list package groups"
- "groupupdate:update a package group or groups"
- "localinstall:install packages with local rpm files"
- "localupdate:update packages with local rpm files"
- "makecache:makes a local yum cache"
- "provides:find out which package provides some feature or file"
- "whatprovides:find out which package provides some feature or file"
- "resolvedep:list packages providing the specified dependencies"
- "search:find any packages matching pattern"
- "shell:enter the 'yum shell'"
- "update:update one or more packages"
- "upgrade:upgrade one or more packages"
- )
-
- if (( CURRENT == 1 )); then
- _describe -t commands 'yum command' _yum_cmds || compadd "$@"
- else
- local curcontext="$curcontext"
-
- cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
- # Deal with any aliases
- case $cmd in
- remove) cmd="erase";;
- whatprovides) cmd="provides";;
- upgrade) cmd="update";;
- esac
-
- if (( $#cmd )); then
- curcontext="${curcontext%:*:*}:yum-${cmd}:"
-
- local update_policy
- zstyle -s ":completion:${curcontext}:" cache-policy update_policy
- if [[ -z "$update_policy" ]]; then
- zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
- fi
-
- _call_function ret _yum_$cmd || _message 'no more arguments'
- else
- _message "unknown yum command: $words[1]"
- fi
- return ret
- fi
+ local -a _yum_cmds
+ _yum_cmds=(
+ "install:install the latest version of a package or group of packages"
+ "erase:remove an installed package (with its dependencies)"
+ "remove:remove an installed package (with its dependencies)"
+ "clean:clean local yum cache"
+ "deplist:gives a list of all dependencies for a package"
+ "check-update:check if any updates are available"
+ "info:get description of available packages"
+ "list:is used to list various information about packages"
+ "groupinfo:get info on package groups"
+ "groupinstall:install a package group or groups"
+ "groupremove:remove a package group or groups"
+ "grouplist:list package groups"
+ "groupupdate:update a package group or groups"
+ "localinstall:install packages with local rpm files"
+ "localupdate:update packages with local rpm files"
+ "makecache:makes a local yum cache"
+ "provides:find out which package provides some feature or file"
+ "whatprovides:find out which package provides some feature or file"
+ "resolvedep:list packages providing the specified dependencies"
+ "search:find any packages matching pattern"
+ "shell:enter the 'yum shell'"
+ "update:update one or more packages"
+ "upgrade:upgrade one or more packages"
+ "update-to:update one or more packages taking obsoletes into account"
+ "upgrade-to:upgrade one or more packages taking obsoletes into account"
+ "history:view past transactions"
+ "help:produce help for all or given command"
+ "load-transaction:load a saved transaction from a textfile"
+ "load-ts:load a saved transaction from a textfile"
+ "check:Check for problems in the rpmdb"
+ "reinstall:reinstall a package"
+ "downgrade:downgrade a package"
+ "repolist:Display the configured software repositories"
+ "distribution-synchronization:Synchronize installed packages to the latest available versions"
+ "distro-sync:Synchronize installed packages to the latest available versions"
+ )
+
+ if (( CURRENT == 1 )); then
+ _describe -t commands 'yum command' _yum_cmds || compadd "$@"
+ else
+ local curcontext="$curcontext"
+
+ cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
+ # Deal with any aliases
+ case $cmd in
+ remove) cmd="erase";;
+ whatprovides) cmd="provides";;
+ upgrade) cmd="update";;
+ upgrade-to) cmd="update";;
+ update-to) cmd="update";;
+ load-ts) cmd="load-transaction";;
+ distro-sync) cmd="distribution-synchronization";;
+ esac
+
+ if (( $#cmd )); then
+ curcontext="${curcontext%:*:*}:yum-${cmd}:"
+
+ local update_policy
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
+ fi
+
+ if [ "$cmd" = "help" ]; then
+ if (( CURRENT == 2 )); then
+ local -a _yum_cmd_names
+ _yum_cmd_names=(${_yum_cmds%%:*})
+ _describe -t commands 'commands' _yum_cmd_names
+ else
+ _message 'no more arguments'
+ fi
+ else
+ _call_function ret _yum_$cmd || _message 'no more arguments'
+ fi
+ else
+ _message "unknown yum command: $words[1]"
+ fi
+ return ret
+ fi
+}
+
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ local -a chkargs
+ #chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ #chkargs=("dependencies" "duplicates" "all") # according to help
+ chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ _describe -t arguments 'check arguments' chkargs
+ fi
+ return 0
+}
+
+# Expand next argument after 'yum repolist'
+_yum_repolist() {
+ if (( CURRENT == 2 )); then
+ local -a suggests
+ suggests=("all" "enabled" "disabled")
+ _describe -t arguments 'repolist arguments' suggests
+ fi
+ return 0
+}
+
+_ids() {
+ # the last argument will be the first valid transaction ID to be suggested
+ # all other arguments are forwarded to compadd
+ #
+ # maxid is the last transaction ID known to yum
+ # minusone is the number of arguments provided to _ids minus one
+ local maxid
+ local minusone
+
+ maxid=$(yum history stats | grep Transactions | sed "s/.*: //")
+ ((minusone=$#-1))
+ compadd "${(@)@[1,$minusone]}" $(echo {$@[$#]..$maxid})
}
+_ranges() {
+ if compset -P '*..'; then
+ _ids ${(S)IPREFIX#..}
+ else
+ _ids -S '..' 1
+ fi
+}
+
+# Expand next argument after 'yum history'
+_yum_history() {
+ if (( CURRENT == 2 )); then
+ local -a historycommands
+ historycommands=('info' 'list' 'packages-list' 'packages-info' 'summary' 'addon-info' 'redo' 'undo' 'roll-back' 'new' 'sync' 'stats')
+ _describe -t commands 'yum history command' historycommands
+ fi
+ if (( CURRENT == 3 )); then
+ local -a ID_commands
+ local -a ID_range_commands
+ local -a package_commands
+ local -a suggests
+ suggests=()
+ #ID_commands=('summary' 'info' 'list' 'stats' 'addon-info')
+ ID_commands=('addon-info')
+ ID_range_commands=('summary' 'info' 'list' 'stats')
+ package_commands=('summary' 'info' 'list' 'stats' 'packages-list' 'packages-info')
+ #package_commands=('packages-list' 'packages-info')
+ # packages-list, packages-info : needs package name
+ # summary, info, list, stats : ID, ID range, package name
+ # addon-info : ID
+ # redo, undo, roll-back, sync : unknown
+ if [[ -n "${ID_commands[(r)$words[2]]}" ]]; then
+ suggests+=(':special IDs:(last)')
+ suggests+=(':IDs:_ids 1')
+ fi
+ if [[ -n "${ID_range_commands[(r)$words[2]]}" ]]; then
+ suggests+=(':transaction ranges:_ranges')
+ suggests+=(':all transactions:(all)')
+ fi
+ if [[ -n "${package_commands[(r)$words[2]]}" ]]; then
+ _yum_installed_pkgs
+ #suggests+=(":packages:($_installed_pkgs)")
+ suggests+=(":packages:_yum_act_on_installed_pkgs")
+ fi
+ if [[ 0 -eq ${#suggests} ]] ; then
+ _message "unknown expansion for: yum history $words[2]"
+ else
+ _alternative $suggests
+ fi
+ fi
+ if (( CURRENT == 4 )); then
+ if [ "$words[2]" = "addon-info" ]; then
+ local -a historyargs
+ historyargs=(saved_tx)
+ _describe 'additional option' historyargs
+ fi
+ fi
+}
+
+
# Fills the all pkg cache
_yum_all_pkgs()
{
- if ( [[ ${+_all_pkgs} -eq 0 ]] || _cache_invalid ALL ) &&
- ! _retrieve_cache ALL;
- then
- _all_pkgs=( $(yum -C list all | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache ALL _all_pkgs
- fi
+ if ( [[ ${+_all_pkgs} -eq 0 ]] || _cache_invalid ALL ) &&
+ ! _retrieve_cache ALL;
+then
+ _all_pkgs=( $(yum -C list all | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache ALL _all_pkgs
+fi
}
# Fills the installed pkg cache
_yum_installed_pkgs()
{
- if ( [[ ${+_installed_pkgs} -eq 0 ]] || _cache_invalid INSTALLED ) &&
- ! _retrieve_cache INSTALLED;
- then
- _installed_pkgs=( $(yum -C list installed | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache INSTALLED _installed_pkgs
- fi
+ if ( [[ ${+_installed_pkgs} -eq 0 ]] || _cache_invalid INSTALLED ) &&
+ ! _retrieve_cache INSTALLED;
+then
+ _installed_pkgs=( $(yum -C list installed | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache INSTALLED _installed_pkgs
+fi
}
# Fills the available pkg cache
_yum_available_pkgs()
{
- if ( [[ ${+_available_pkgs} -eq 0 ]] || _cache_invalid AVAILABLE ) &&
- ! _retrieve_cache AVAILABLE;
- then
- _available_pkgs=( $(yum -C list available | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache AVAILABLE _available_pkgs
- fi
+ if ( [[ ${+_available_pkgs} -eq 0 ]] || _cache_invalid AVAILABLE ) &&
+ ! _retrieve_cache AVAILABLE;
+then
+ _available_pkgs=( $(yum -C list available | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache AVAILABLE _available_pkgs
+fi
}
# Fills the upgrade pkg cache
_yum_upgrade_pkgs()
{
- if ( [[ ${+_upgrade_pkgs} -eq 0 ]] || _cache_invalid UPGRADE ) &&
- ! _retrieve_cache UPGRADE;
- then
- _upgrade_pkgs=( $(yum -C list upgrade | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache UPGRADE _upgrade_pkgs
- fi
+ if ( [[ ${+_upgrade_pkgs} -eq 0 ]] || _cache_invalid UPGRADE ) &&
+ ! _retrieve_cache UPGRADE;
+then
+ _upgrade_pkgs=( $(yum -C list upgrade | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache UPGRADE _upgrade_pkgs
+fi
}
# Gets the list of defined repos
yum_repos() {
- local trepo
- local -a tarray
- tarray=( $(egrep -h '(^\[.*\]|^enabled.*=)' /etc/yum.repos.d/*.repo /etc/yum.conf | sed -e 's/ //g' | sed -e 's/\[//g' | sed -e 's/\].*$//g' 2>/dev/null) )
- local -i eindex=0
- local -i dindex=0
- for line in $tarray; do
- if [[ "$line" = "enabled=1" ]]; then
- enabled_yum_repos=($enabled_yum_repos $trepo)
- elif [[ "$line" = "enabled=0" ]]; then
- disabled_yum_repos=($disabled_yum_repos $trepo)
- elif [[ "$line" != "main" ]]; then
- trepo=$line
- fi
- done
+ local trepo
+ local -a tarray
+ tarray=( $(egrep -h '(^\[.*\]|^enabled.*=)' /etc/yum.repos.d/*.repo /etc/yum.conf | sed -e 's/ //g' | sed -e 's/\[//g' | sed -e 's/\].*$//g' 2>/dev/null) )
+ local -i eindex=0
+ local -i dindex=0
+ for line in $tarray; do
+ if [[ "$line" = "enabled=1" ]]; then
+ enabled_yum_repos=($enabled_yum_repos $trepo)
+ elif [[ "$line" = "enabled=0" ]]; then
+ disabled_yum_repos=($disabled_yum_repos $trepo)
+ elif [[ "$line" != "main" ]]; then
+ trepo=$line
+ fi
+ done
}
(( $+functions[_yum_disabled_repos_list] )) || _yum_disabled_repos_list()
{
- compset -P '*,'
- compset -S ',*'
- yum_repos
- compadd "$@" -a -- disabled_yum_repos
+ compset -P '*,'
+ compset -S ',*'
+ yum_repos
+ compadd "$@" -a -- disabled_yum_repos
}
(( $+functions[_yum_enabled_repos_list] )) || _yum_enabled_repos_list()
{
- compset -P '*,'
- compset -S ',*'
- yum_repos
- compadd "$@" -a -- enabled_yum_repos
+ compset -P '*,'
+ compset -S ',*'
+ yum_repos
+ compadd "$@" -a -- enabled_yum_repos
+}
+
+# Suggest installed packages
+_yum_act_on_installed_pkgs() {
+ _yum_installed_pkgs
+ compadd "$@" -a -- _installed_pkgs
+}
+
+# Completion function for distribution-synchronization|distro-sync
+(( $+functions[_yum_distribution-synchronization] )) || _yum_distribution-synchronization()
+{
+ _yum_act_on_installed_pkgs
}
# Completion function for erase|remove
(( $+functions[_yum_erase] )) || _yum_erase()
{
- _yum_installed_pkgs
- compadd "$@" -a -- _installed_pkgs
+ _yum_act_on_installed_pkgs
+}
+
+# Completion function for downgrade
+(( $+functions[_yum_downgrade] )) || _yum_downgrade()
+{
+ _yum_act_on_installed_pkgs
+}
+
+# Completion function for reinstall
+(( $+functions[_yum_reinstall] )) || _yum_reinstall()
+{
+ _yum_act_on_installed_pkgs
}
# Completion function for install
(( $+functions[_yum_install] )) || _yum_install()
{
- if ! [[ $PREFIX == */* ]]; then
- _yum_available_pkgs
- fi
+ if ! [[ $PREFIX == */* ]]; then
+ _yum_available_pkgs
+ fi
- local ret=1
- _tags files packages
- while _tags; do
- if _requested files; then
- compadd "$@" -a -- _available_pkgs
- fi
- if _requested packages; then
- _call_function - _yum_localinstall
- fi
- (( ret )) || break
- done
- return ret
+ local ret=1
+ _tags files packages
+ while _tags; do
+ if _requested files; then
+ compadd "$@" -a -- _available_pkgs
+ fi
+ if _requested packages; then
+ _call_function - _yum_localinstall
+ fi
+ (( ret )) || break
+ done
+ return ret
+}
+
+# Completion function for load-transaction
+(( $+functions[_yum_load-transaction] )) || _yum_load-transaction()
+{
+ _files
}
# Completion function for localinstall
(( $+functions[_yum_localinstall] )) || _yum_localinstall()
{
- _files -/ -g '(#i)*.rpm(-.)'
+ _files -/ -g '(#i)*.rpm(-.)'
}
# Completion function for localupdate
(( $+functions[_yum_localupdate] )) || _yum_localupdate()
{
- _files -/ -g '(#i)*.rpm(-.)'
+ _files -/ -g '(#i)*.rpm(-.)'
}
# Completion function for update/upgrade
(( $+functions[_yum_update] )) || _yum_update()
{
- _yum_upgrade_pkgs
- compadd "$@" -a -- _upgrade_pkgs
+ _yum_upgrade_pkgs
+ compadd "$@" -a -- _upgrade_pkgs
}
# Completion function for deplist
(( $+functions[_yum_deplist] )) || _yum_deplist()
{
- _yum_available_pkgs
- compadd "$@" -a -- _available_pkgs
+ _yum_available_pkgs
+ compadd "$@" -a -- _available_pkgs
}
_yum_all()
{
- _yum_all_pkgs
- compadd "$@" -a -- _all_pkgs
+ _yum_all_pkgs
+ compadd "$@" -a -- _all_pkgs
}
_yum_list_or_info()
{
- local -a listlist
- listlist=(
- "all:all packages in repositories"
- "available:packages available in repositories"
- "updates:packages with updates available"
- "installed:installed packages"
- "extras:packages installed that are not available in any yum repository"
- "obsoletes:packages installed that are obsoleted"
- "recent:packages recently added to repositories"
- )
-
- if (( CURRENT == 2 )); then
- _describe -t yum-list-subcmds "Yum info/list sub-commands" listlist || _yum_all
- else
- local subcmd
- subcmd="${${listlist[(r)$words[2]:*]%%:*}}"
- # offer packages selected by the subcommand
- case $subcmd in
- all) _yum_all;;
- installed) _yum_erase;;
- available) _yum_install;;
- updates) _yum_update;;
- esac
- fi
+ local -a listlist
+ listlist=(
+ "all:all packages in repositories"
+ "available:packages available in repositories"
+ "updates:packages with updates available"
+ "installed:installed packages"
+ "extras:packages installed that are not available in any yum repository"
+ "obsoletes:packages installed that are obsoleted"
+ "recent:packages recently added to repositories"
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t yum-list-subcmds "Yum info/list sub-commands" listlist || _yum_all
+ else
+ local subcmd
+ subcmd="${${listlist[(r)$words[2]:*]%%:*}}"
+ # offer packages selected by the subcommand
+ case $subcmd in
+ all) _yum_all;;
+ installed) _yum_erase;;
+ available) _yum_install;;
+ updates) _yum_update;;
+ esac
+ fi
}
# Completion function for list
(( $+functions[_yum_list] )) || _yum_list()
{
- _yum_list_or_info
+ _yum_list_or_info
}
# Completion function for info
(( $+functions[_yum_info] )) || _yum_info()
{
- _yum_list_or_info
+ _yum_list_or_info
}
# Completion function for provides|whatprovides
(( $+functions[_yum_provides] )) || _yum_provides()
{
- _files
+ _files
}
# Completion function for resolvedep
(( $+functions[_yum_resolvedep] )) || _yum_resolvedep()
{
- _files
+ _files
}
# Completion function for clean
(( $+functions[_yum_clean] )) || _yum_clean()
{
- local -a cleanlist
- cleanlist=(
- "all:all cache"
- "cache:all cache"
- "dbcache:DB cache"
- "headers:cache headers"
- "packages:cache packages"
- "metadata:cache meta-data"
- )
-
- if (( CURRENT == 2 )); then
- _describe -t yum-clean-subcmds "Yum clean sub-commands" cleanlist
- fi
+ local -a cleanlist
+ cleanlist=(
+ "all:all cache"
+ "cache:all cache"
+ "dbcache:DB cache"
+ "headers:cache headers"
+ "packages:cache packages"
+ "metadata:cache meta-data"
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t yum-clean-subcmds "Yum clean sub-commands" cleanlist
+ fi
}
_yum_caching_policy()
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: PATCH Completion for _yum (contains FIXMEs)
2016-10-31 12:09 ` Paul Seyfert
@ 2016-11-10 10:18 ` Paul Seyfert
2016-11-10 15:49 ` Oliver Kiddle
0 siblings, 1 reply; 19+ messages in thread
From: Paul Seyfert @ 2016-11-10 10:18 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 1613 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Hi again,
>>> [snap]
>>
>> This looks like it would be better written with _alternative:
>>
>> alts=()
>> [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=( 'id-ranges:id ranges:_id-ranges' )
>> [[ -n "${package_commands[(r)$words[2]]}" ]] && alts+=( 'packages:packages:...' )
>> ⋮
>> (( ${+alts[1]} )) && _alternative "$alts[@]"
>>
>> To see the difference, set the «group-name» style to «''» (and
>> optionally the «format» style to something with «%d» in it). You can
>> see this in «ssh <TAB>» too (compare with/without those two styles).
>
Now done as you suggest. Nice indeed (and I learned what the first
packages in 'packages:packages:...' is good for).
Updated patches attached.
Cheers,
Paul
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJYJEloAAoJEPOmP9OjPXmrzfAQAIiH8kEQtqh+70seIC52xehs
/xi10Pb18HqWJbWb7iBrk6/0+UE3ZX6M/q7PSSFaAfRCPsRcUUiS2bHgEHCzkhrk
i0c8WUiDC1CFSDHdlRxxnRt6jpyoVwlPWKLLaCjR/MwrBspAUWrOucDKtWMFbclM
fFb8M0XO4MgCDhoAE66Gf0PH9ezoa5gBqyClIv9M37bJpvNSCXXs0xCjtskJuTWa
49LEjKk4TzTNDnLGUZPKyIaki2tPaKG5NzYKeQZZvPn2Hrd4nm0YWP2/RKhwozuU
JipcLPMolJabHOrbxA9dATpUPtrUdJB+NU7w9NiAIOy8nON0xpib/Rlk2/CiRgxG
g2DUj7THibx261LZE/zqk5EgrIq/WQCHStq30Jyl0J9APFbFeEhSNl1DYMRYHqG6
56HB1yUrNVgaMFxm9qRTecv0lIyznBuR0yhHBwRTeRIQMK/+fiT3f92kGdwOZMSU
EBXADAub7Mp162WlU3Lb1/owdRYL6PgbSDXkbur5oK8an6kxUs7Jr+kTpiQrlzBR
Uk2sW7ECdGa/jUQFZK8fOHSK0KmRfVnK0Vfvcnp/WO9sG+eDVukK8S3wdsUFTYRU
39ChymUXI26d9R3CCcMv16R9DM26KQu4iAoMO+HLjac+vjLfWsAXDICU5LVwCNku
f7p+JVWq5pia0OiEi0oa
=TbJP
-----END PGP SIGNATURE-----
[-- Attachment #2: extend-yum-completion3.patch --]
[-- Type: text/x-patch, Size: 20536 bytes --]
diff --git a/Completion/Redhat/Command/_yum b/Completion/Redhat/Command/_yum
index f453806..f354261 100644
--- a/Completion/Redhat/Command/_yum
+++ b/Completion/Redhat/Command/_yum
@@ -3,293 +3,434 @@
# Main dispatcher
_yum()
{
- local curcontext="$curcontext" state lstate line
-
- _arguments -s \
- '(- *)'{-h,--help}'[show the help message]' \
- '(-t --tolerant)'{-t,--tolerant}'[be tolerant of errors]' \
- '(-C --cacheonly)'{-C,--cacheonly}'[run entirely from cache]' \
- '(-c --config)'{-c,--config=}'[config file location]:Yum conf file:_files' \
- '(-R --randomwait)'{-R,--randomwait=}'[maximum command wait time (in minutes)]:max wait time' \
- '(-d --debuglevel)'{-d,--debuglevel=}'[debug level (0-10)]:debug level' \
- '(-e --errorlevel)'{-e,--errorlevel=}'[error level (0-10)]:error level' \
- '(-y --assumeyes)'{-y,--assumeyes}'[answer yes for all questions]' \
- '--installroot=[set install root]:install root:_files -/' \
- '*--enablerepo=[enable or or more repositories]:repos to enable:_yum_disabled_repos_list' \
- '*--disablerepo=[disable one or more repositories]:disable repos:_yum_enabled_repos_list' \
- {*-x,*--exclude=}'[exclude package(s) by name or glob]:exclude packages' \
- '--version[show yum version]' \
- '--obsoletes[enable obsoletes processing during updates]' \
- '--nogpgcheck[disable gpg signature checking]' \
- '--noplugins[disable yum plugins]' \
- '--disablepresto[disable Presto plugin and don''''t download any deltarpms]' \
- '*::yum command:_yum_command'
+ local curcontext="$curcontext" state lstate line
+
+ _arguments -s \
+ '(- *)'{-h,--help}'[show the help message]' \
+ '(-t --tolerant)'{-t,--tolerant}'[be tolerant of errors]' \
+ '(-C --cacheonly)'{-C,--cacheonly}'[run entirely from cache]' \
+ '(-c --config)'{-c,--config=}'[config file location]:Yum conf file:_files' \
+ '(-R --randomwait)'{-R,--randomwait=}'[maximum command wait time (in minutes)]:max wait time' \
+ '(-d --debuglevel)'{-d,--debuglevel=}'[debug level (0-10)]:debug level' \
+ '(-e --errorlevel)'{-e,--errorlevel=}'[error level (0-10)]:error level' \
+ '(-y --assumeyes)'{-y,--assumeyes}'[answer yes for all questions]' \
+ '--installroot=[set install root]:install root:_files -/' \
+ '*--enablerepo=[enable or or more repositories]:repos to enable:_yum_disabled_repos_list' \
+ '*--disablerepo=[disable one or more repositories]:disable repos:_yum_enabled_repos_list' \
+ {*-x,*--exclude=}'[exclude package(s) by name or glob]:exclude packages' \
+ '--version[show yum version]' \
+ '--obsoletes[enable obsoletes processing during updates]' \
+ '--nogpgcheck[disable gpg signature checking]' \
+ '--noplugins[disable yum plugins]' \
+ '--disablepresto[disable Presto plugin and don''''t download any deltarpms]' \
+ '*::yum command:_yum_command'
}
(( $+functions[_yum_command] )) || _yum_command()
{
- local -a _yum_cmds
- _yum_cmds=(
- "install:install the latest version of a package or group of packages"
- "erase:remove an installed package (with its dependencies)"
- "remove:remove an installed package (with its dependencies)"
- "clean:clean local yum cache"
- "deplist:gives a list of all dependencies for a package"
- "check-update:check if any updates are available"
- "info:get description of available packages"
- "list:is used to list various information about packages"
- "groupinfo:get info on package groups"
- "groupinstall:install a package group or groups"
- "groupremove:remove a package group or groups"
- "grouplist:list package groups"
- "groupupdate:update a package group or groups"
- "localinstall:install packages with local rpm files"
- "localupdate:update packages with local rpm files"
- "makecache:makes a local yum cache"
- "provides:find out which package provides some feature or file"
- "whatprovides:find out which package provides some feature or file"
- "resolvedep:list packages providing the specified dependencies"
- "search:find any packages matching pattern"
- "shell:enter the 'yum shell'"
- "update:update one or more packages"
- "upgrade:upgrade one or more packages"
- )
-
- if (( CURRENT == 1 )); then
- _describe -t commands 'yum command' _yum_cmds || compadd "$@"
- else
- local curcontext="$curcontext"
-
- cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
- # Deal with any aliases
- case $cmd in
- remove) cmd="erase";;
- whatprovides) cmd="provides";;
- upgrade) cmd="update";;
- esac
-
- if (( $#cmd )); then
- curcontext="${curcontext%:*:*}:yum-${cmd}:"
-
- local update_policy
- zstyle -s ":completion:${curcontext}:" cache-policy update_policy
- if [[ -z "$update_policy" ]]; then
- zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
- fi
-
- _call_function ret _yum_$cmd || _message 'no more arguments'
- else
- _message "unknown yum command: $words[1]"
- fi
- return ret
- fi
+ local -a _yum_cmds
+ _yum_cmds=(
+ "install:install the latest version of a package or group of packages"
+ "erase:remove an installed package (with its dependencies)"
+ "remove:remove an installed package (with its dependencies)"
+ "clean:clean local yum cache"
+ "deplist:gives a list of all dependencies for a package"
+ "check-update:check if any updates are available"
+ "info:get description of available packages"
+ "list:is used to list various information about packages"
+ "groupinfo:get info on package groups"
+ "groupinstall:install a package group or groups"
+ "groupremove:remove a package group or groups"
+ "grouplist:list package groups"
+ "groupupdate:update a package group or groups"
+ "localinstall:install packages with local rpm files"
+ "localupdate:update packages with local rpm files"
+ "makecache:makes a local yum cache"
+ "provides:find out which package provides some feature or file"
+ "whatprovides:find out which package provides some feature or file"
+ "resolvedep:list packages providing the specified dependencies"
+ "search:find any packages matching pattern"
+ "shell:enter the 'yum shell'"
+ "update:update one or more packages"
+ "upgrade:upgrade one or more packages"
+ "update-to:update one or more packages taking obsoletes into account"
+ "upgrade-to:upgrade one or more packages taking obsoletes into account"
+ "history:view past transactions"
+ "help:produce help for all or given command"
+ "load-transaction:load a saved transaction from a textfile"
+ "load-ts:load a saved transaction from a textfile"
+ "check:Check for problems in the rpmdb"
+ "reinstall:reinstall a package"
+ "downgrade:downgrade a package"
+ "repolist:Display the configured software repositories"
+ "distribution-synchronization:Synchronize installed packages to the latest available versions"
+ "distro-sync:Synchronize installed packages to the latest available versions"
+ )
+
+ if (( CURRENT == 1 )); then
+ _describe -t commands 'yum command' _yum_cmds || compadd "$@"
+ else
+ local curcontext="$curcontext"
+
+ cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
+ # Deal with any aliases
+ case $cmd in
+ remove) cmd="erase";;
+ whatprovides) cmd="provides";;
+ upgrade) cmd="update";;
+ upgrade-to) cmd="update";;
+ update-to) cmd="update";;
+ load-ts) cmd="load-transaction";;
+ distro-sync) cmd="distribution-synchronization";;
+ esac
+
+ if (( $#cmd )); then
+ curcontext="${curcontext%:*:*}:yum-${cmd}:"
+
+ local update_policy
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
+ fi
+
+ if [ "$cmd" = "help" ]; then
+ if (( CURRENT == 2 )); then
+ local -a _yum_cmd_names
+ _yum_cmd_names=(${_yum_cmds%%:*})
+ _describe -t commands 'commands' _yum_cmd_names
+ else
+ _message 'no more arguments'
+ fi
+ else
+ _call_function ret _yum_$cmd || _message 'no more arguments'
+ fi
+ else
+ _message "unknown yum command: $words[1]"
+ fi
+ return ret
+ fi
+}
+
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ local -a chkargs
+ #chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ #chkargs=("dependencies" "duplicates" "all") # according to help
+ chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ _describe -t arguments 'check arguments' chkargs
+ fi
+ return 0
+}
+
+# Expand next argument after 'yum repolist'
+_yum_repolist() {
+ if (( CURRENT == 2 )); then
+ local -a suggests
+ suggests=("all" "enabled" "disabled")
+ _describe -t arguments 'repolist arguments' suggests
+ fi
+ return 0
+}
+
+_ids() {
+ # the last argument will be the first valid transaction ID to be suggested
+ # all other arguments are forwarded to compadd
+ #
+ # maxid is the last transaction ID known to yum
+ # minusone is the number of arguments provided to _ids minus one
+ local maxid
+ local minusone
+
+ maxid=$(yum history stats | grep Transactions | sed "s/.*: //")
+ ((minusone=$#-1))
+ compadd "${(@)@[1,$minusone]}" $(echo {$@[$#]..$maxid})
}
+_ranges() {
+ if compset -P '*..'; then
+ _ids ${(S)IPREFIX#..}
+ else
+ _ids -S '..' 1
+ fi
+}
+
+# Expand next argument after 'yum history'
+_yum_history() {
+ if (( CURRENT == 2 )); then
+ local -a historycommands
+ historycommands=('info' 'list' 'packages-list' 'packages-info' 'summary' 'addon-info' 'redo' 'undo' 'roll-back' 'new' 'sync' 'stats')
+ _describe -t commands 'yum history command' historycommands
+ fi
+ if (( CURRENT == 3 )); then
+ local -a ID_commands
+ local -a ID_range_commands
+ local -a package_commands
+ local -a alts
+ alts=()
+ #ID_commands=('summary' 'info' 'list' 'stats' 'addon-info')
+ ID_commands=('addon-info')
+ ID_range_commands=('summary' 'info' 'list' 'stats')
+ package_commands=('summary' 'info' 'list' 'stats' 'packages-list' 'packages-info')
+ #package_commands=('packages-list' 'packages-info')
+ # packages-list, packages-info : needs package name
+ # summary, info, list, stats : ID, ID range, package name
+ # addon-info : ID
+ # redo, undo, roll-back, sync : unknown
+
+ [[ -n "${ID_commands[(r)$words[2]]}" ]] && alts+=('special:special IDs:(last)')
+ [[ -n "${ID_commands[(r)$words[2]]}" ]] && alts+=('regular:IDs:_ids 1')
+ [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=('regular:transaction ranges:_ranges')
+ [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=('special:all transactions:(all)')
+ [[ -n "${package_commands[(r)$words[2]]}" ]] && alts+=("packages:packages:_yum_act_on_installed_pkgs")
+
+ (( ${+alts[1]} )) && _alternative "$alts[@]" || \
+ _message "unknown expansion for: yum history $words[2]"
+ fi
+ if (( CURRENT == 4 )); then
+ if [ "$words[2]" = "addon-info" ]; then
+ local -a historyargs
+ historyargs=(saved_tx)
+ _describe 'additional option' historyargs
+ fi
+ fi
+}
+
+
# Fills the all pkg cache
_yum_all_pkgs()
{
- if ( [[ ${+_all_pkgs} -eq 0 ]] || _cache_invalid ALL ) &&
- ! _retrieve_cache ALL;
- then
- _all_pkgs=( $(yum -C list all | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache ALL _all_pkgs
- fi
+ if ( [[ ${+_all_pkgs} -eq 0 ]] || _cache_invalid ALL ) &&
+ ! _retrieve_cache ALL;
+then
+ _all_pkgs=( $(yum -C list all | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache ALL _all_pkgs
+fi
}
# Fills the installed pkg cache
_yum_installed_pkgs()
{
- if ( [[ ${+_installed_pkgs} -eq 0 ]] || _cache_invalid INSTALLED ) &&
- ! _retrieve_cache INSTALLED;
- then
- _installed_pkgs=( $(yum -C list installed | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache INSTALLED _installed_pkgs
- fi
+ if ( [[ ${+_installed_pkgs} -eq 0 ]] || _cache_invalid INSTALLED ) &&
+ ! _retrieve_cache INSTALLED;
+then
+ _installed_pkgs=( $(yum -C list installed | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache INSTALLED _installed_pkgs
+fi
}
# Fills the available pkg cache
_yum_available_pkgs()
{
- if ( [[ ${+_available_pkgs} -eq 0 ]] || _cache_invalid AVAILABLE ) &&
- ! _retrieve_cache AVAILABLE;
- then
- _available_pkgs=( $(yum -C list available | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache AVAILABLE _available_pkgs
- fi
+ if ( [[ ${+_available_pkgs} -eq 0 ]] || _cache_invalid AVAILABLE ) &&
+ ! _retrieve_cache AVAILABLE;
+then
+ _available_pkgs=( $(yum -C list available | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache AVAILABLE _available_pkgs
+fi
}
# Fills the upgrade pkg cache
_yum_upgrade_pkgs()
{
- if ( [[ ${+_upgrade_pkgs} -eq 0 ]] || _cache_invalid UPGRADE ) &&
- ! _retrieve_cache UPGRADE;
- then
- _upgrade_pkgs=( $(yum -C list upgrade | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache UPGRADE _upgrade_pkgs
- fi
+ if ( [[ ${+_upgrade_pkgs} -eq 0 ]] || _cache_invalid UPGRADE ) &&
+ ! _retrieve_cache UPGRADE;
+then
+ _upgrade_pkgs=( $(yum -C list upgrade | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache UPGRADE _upgrade_pkgs
+fi
}
# Gets the list of defined repos
yum_repos() {
- local trepo
- local -a tarray
- tarray=( $(egrep -h '(^\[.*\]|^enabled.*=)' /etc/yum.repos.d/*.repo /etc/yum.conf | sed -e 's/ //g' | sed -e 's/\[//g' | sed -e 's/\].*$//g' 2>/dev/null) )
- local -i eindex=0
- local -i dindex=0
- for line in $tarray; do
- if [[ "$line" = "enabled=1" ]]; then
- enabled_yum_repos=($enabled_yum_repos $trepo)
- elif [[ "$line" = "enabled=0" ]]; then
- disabled_yum_repos=($disabled_yum_repos $trepo)
- elif [[ "$line" != "main" ]]; then
- trepo=$line
- fi
- done
+ local trepo
+ local -a tarray
+ tarray=( $(egrep -h '(^\[.*\]|^enabled.*=)' /etc/yum.repos.d/*.repo /etc/yum.conf | sed -e 's/ //g' | sed -e 's/\[//g' | sed -e 's/\].*$//g' 2>/dev/null) )
+ local -i eindex=0
+ local -i dindex=0
+ for line in $tarray; do
+ if [[ "$line" = "enabled=1" ]]; then
+ enabled_yum_repos=($enabled_yum_repos $trepo)
+ elif [[ "$line" = "enabled=0" ]]; then
+ disabled_yum_repos=($disabled_yum_repos $trepo)
+ elif [[ "$line" != "main" ]]; then
+ trepo=$line
+ fi
+ done
}
(( $+functions[_yum_disabled_repos_list] )) || _yum_disabled_repos_list()
{
- compset -P '*,'
- compset -S ',*'
- yum_repos
- compadd "$@" -a -- disabled_yum_repos
+ compset -P '*,'
+ compset -S ',*'
+ yum_repos
+ compadd "$@" -a -- disabled_yum_repos
}
(( $+functions[_yum_enabled_repos_list] )) || _yum_enabled_repos_list()
{
- compset -P '*,'
- compset -S ',*'
- yum_repos
- compadd "$@" -a -- enabled_yum_repos
+ compset -P '*,'
+ compset -S ',*'
+ yum_repos
+ compadd "$@" -a -- enabled_yum_repos
+}
+
+# Suggest installed packages
+_yum_act_on_installed_pkgs() {
+ _yum_installed_pkgs
+ compadd "$@" -a -- _installed_pkgs
+}
+
+# Completion function for distribution-synchronization|distro-sync
+(( $+functions[_yum_distribution-synchronization] )) || _yum_distribution-synchronization()
+{
+ _yum_act_on_installed_pkgs "$@"
}
# Completion function for erase|remove
(( $+functions[_yum_erase] )) || _yum_erase()
{
- _yum_installed_pkgs
- compadd "$@" -a -- _installed_pkgs
+ _yum_act_on_installed_pkgs "$@"
+}
+
+# Completion function for downgrade
+(( $+functions[_yum_downgrade] )) || _yum_downgrade()
+{
+ _yum_act_on_installed_pkgs "$@"
+}
+
+# Completion function for reinstall
+(( $+functions[_yum_reinstall] )) || _yum_reinstall()
+{
+ _yum_act_on_installed_pkgs "$@"
}
# Completion function for install
(( $+functions[_yum_install] )) || _yum_install()
{
- if ! [[ $PREFIX == */* ]]; then
- _yum_available_pkgs
- fi
+ if ! [[ $PREFIX == */* ]]; then
+ _yum_available_pkgs
+ fi
- local ret=1
- _tags files packages
- while _tags; do
- if _requested files; then
- compadd "$@" -a -- _available_pkgs
- fi
- if _requested packages; then
- _call_function - _yum_localinstall
- fi
- (( ret )) || break
- done
- return ret
+ local ret=1
+ _tags files packages
+ while _tags; do
+ if _requested files; then
+ compadd "$@" -a -- _available_pkgs
+ fi
+ if _requested packages; then
+ _call_function - _yum_localinstall
+ fi
+ (( ret )) || break
+ done
+ return ret
+}
+
+# Completion function for load-transaction
+(( $+functions[_yum_load-transaction] )) || _yum_load-transaction()
+{
+ _files
}
# Completion function for localinstall
(( $+functions[_yum_localinstall] )) || _yum_localinstall()
{
- _files -/ -g '(#i)*.rpm(-.)'
+ _files -/ -g '(#i)*.rpm(-.)'
}
# Completion function for localupdate
(( $+functions[_yum_localupdate] )) || _yum_localupdate()
{
- _files -/ -g '(#i)*.rpm(-.)'
+ _files -/ -g '(#i)*.rpm(-.)'
}
# Completion function for update/upgrade
(( $+functions[_yum_update] )) || _yum_update()
{
- _yum_upgrade_pkgs
- compadd "$@" -a -- _upgrade_pkgs
+ _yum_upgrade_pkgs
+ compadd "$@" -a -- _upgrade_pkgs
}
# Completion function for deplist
(( $+functions[_yum_deplist] )) || _yum_deplist()
{
- _yum_available_pkgs
- compadd "$@" -a -- _available_pkgs
+ _yum_available_pkgs
+ compadd "$@" -a -- _available_pkgs
}
_yum_all()
{
- _yum_all_pkgs
- compadd "$@" -a -- _all_pkgs
+ _yum_all_pkgs
+ compadd "$@" -a -- _all_pkgs
}
_yum_list_or_info()
{
- local -a listlist
- listlist=(
- "all:all packages in repositories"
- "available:packages available in repositories"
- "updates:packages with updates available"
- "installed:installed packages"
- "extras:packages installed that are not available in any yum repository"
- "obsoletes:packages installed that are obsoleted"
- "recent:packages recently added to repositories"
- )
-
- if (( CURRENT == 2 )); then
- _describe -t yum-list-subcmds "Yum info/list sub-commands" listlist || _yum_all
- else
- local subcmd
- subcmd="${${listlist[(r)$words[2]:*]%%:*}}"
- # offer packages selected by the subcommand
- case $subcmd in
- all) _yum_all;;
- installed) _yum_erase;;
- available) _yum_install;;
- updates) _yum_update;;
- esac
- fi
+ local -a listlist
+ listlist=(
+ "all:all packages in repositories"
+ "available:packages available in repositories"
+ "updates:packages with updates available"
+ "installed:installed packages"
+ "extras:packages installed that are not available in any yum repository"
+ "obsoletes:packages installed that are obsoleted"
+ "recent:packages recently added to repositories"
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t yum-list-subcmds "Yum info/list sub-commands" listlist || _yum_all
+ else
+ local subcmd
+ subcmd="${${listlist[(r)$words[2]:*]%%:*}}"
+ # offer packages selected by the subcommand
+ case $subcmd in
+ all) _yum_all;;
+ installed) _yum_erase;;
+ available) _yum_install;;
+ updates) _yum_update;;
+ esac
+ fi
}
# Completion function for list
(( $+functions[_yum_list] )) || _yum_list()
{
- _yum_list_or_info
+ _yum_list_or_info
}
# Completion function for info
(( $+functions[_yum_info] )) || _yum_info()
{
- _yum_list_or_info
+ _yum_list_or_info
}
# Completion function for provides|whatprovides
(( $+functions[_yum_provides] )) || _yum_provides()
{
- _files
+ _files
}
# Completion function for resolvedep
(( $+functions[_yum_resolvedep] )) || _yum_resolvedep()
{
- _files
+ _files
}
# Completion function for clean
(( $+functions[_yum_clean] )) || _yum_clean()
{
- local -a cleanlist
- cleanlist=(
- "all:all cache"
- "cache:all cache"
- "dbcache:DB cache"
- "headers:cache headers"
- "packages:cache packages"
- "metadata:cache meta-data"
- )
-
- if (( CURRENT == 2 )); then
- _describe -t yum-clean-subcmds "Yum clean sub-commands" cleanlist
- fi
+ local -a cleanlist
+ cleanlist=(
+ "all:all cache"
+ "cache:all cache"
+ "dbcache:DB cache"
+ "headers:cache headers"
+ "packages:cache packages"
+ "metadata:cache meta-data"
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t yum-clean-subcmds "Yum clean sub-commands" cleanlist
+ fi
}
_yum_caching_policy()
[-- Attachment #3: just_changes3.patch --]
[-- Type: text/x-patch, Size: 6236 bytes --]
diff --git a/Completion/Redhat/Command/_yum b/Completion/Redhat/Command/_yum
index f453806..722f0f5 100644
--- a/Completion/Redhat/Command/_yum
+++ b/Completion/Redhat/Command/_yum
@@ -53,6 +53,18 @@ _yum()
"shell:enter the 'yum shell'"
"update:update one or more packages"
"upgrade:upgrade one or more packages"
+ "update-to:update one or more packages taking obsoletes into account"
+ "upgrade-to:upgrade one or more packages taking obsoletes into account"
+ "history:view past transactions"
+ "help:produce help for all or given command"
+ "load-transaction:load a saved transaction from a textfile"
+ "load-ts:load a saved transaction from a textfile"
+ "check:Check for problems in the rpmdb"
+ "reinstall:reinstall a package"
+ "downgrade:downgrade a package"
+ "repolist:Display the configured software repositories"
+ "distribution-synchronization:Synchronize installed packages to the latest available versions"
+ "distro-sync:Synchronize installed packages to the latest available versions"
)
if (( CURRENT == 1 )); then
@@ -66,6 +78,10 @@ _yum()
remove) cmd="erase";;
whatprovides) cmd="provides";;
upgrade) cmd="update";;
+ upgrade-to) cmd="update";;
+ update-to) cmd="update";;
+ load-ts) cmd="load-transaction";;
+ distro-sync) cmd="distribution-synchronization";;
esac
if (( $#cmd )); then
@@ -77,7 +93,17 @@ _yum()
zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
fi
+ if [ "$cmd" = "help" ]; then
+ if (( CURRENT == 2 )); then
+ local -a _yum_cmd_names
+ _yum_cmd_names=(${_yum_cmds%%:*})
+ _describe -t commands 'commands' _yum_cmd_names
+ else
+ _message 'no more arguments'
+ fi
+ else
_call_function ret _yum_$cmd || _message 'no more arguments'
+ fi
else
_message "unknown yum command: $words[1]"
fi
@@ -85,6 +111,92 @@ _yum()
fi
}
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ local -a chkargs
+ #chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ #chkargs=("dependencies" "duplicates" "all") # according to help
+ chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ _describe -t arguments 'check arguments' chkargs
+ fi
+ return 0
+}
+
+# Expand next argument after 'yum repolist'
+_yum_repolist() {
+ if (( CURRENT == 2 )); then
+ local -a suggests
+ suggests=("all" "enabled" "disabled")
+ _describe -t arguments 'repolist arguments' suggests
+ fi
+ return 0
+}
+
+_ids() {
+ # the last argument will be the first valid transaction ID to be suggested
+ # all other arguments are forwarded to compadd
+ #
+ # maxid is the last transaction ID known to yum
+ # minusone is the number of arguments provided to _ids minus one
+ local maxid
+ local minusone
+
+ maxid=$(yum history stats | grep Transactions | sed "s/.*: //")
+ ((minusone=$#-1))
+ compadd "${(@)@[1,$minusone]}" $(echo {$@[$#]..$maxid})
+}
+
+_ranges() {
+ if compset -P '*..'; then
+ _ids ${(S)IPREFIX#..}
+ else
+ _ids -S '..' 1
+ fi
+}
+
+# Expand next argument after 'yum history'
+_yum_history() {
+ if (( CURRENT == 2 )); then
+ local -a historycommands
+ historycommands=('info' 'list' 'packages-list' 'packages-info' 'summary' 'addon-info' 'redo' 'undo' 'roll-back' 'new' 'sync' 'stats')
+ _describe -t commands 'yum history command' historycommands
+ fi
+ if (( CURRENT == 3 )); then
+ local -a ID_commands
+ local -a ID_range_commands
+ local -a package_commands
+ local -a alts
+ alts=()
+ #ID_commands=('summary' 'info' 'list' 'stats' 'addon-info')
+ ID_commands=('addon-info')
+ ID_range_commands=('summary' 'info' 'list' 'stats')
+ package_commands=('summary' 'info' 'list' 'stats' 'packages-list' 'packages-info')
+ #package_commands=('packages-list' 'packages-info')
+ # packages-list, packages-info : needs package name
+ # summary, info, list, stats : ID, ID range, package name
+ # addon-info : ID
+ # redo, undo, roll-back, sync : unknown
+
+ [[ -n "${ID_commands[(r)$words[2]]}" ]] && alts+=('special:special IDs:(last)')
+ [[ -n "${ID_commands[(r)$words[2]]}" ]] && alts+=('regular:IDs:_ids 1')
+ [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=('regular:transaction ranges:_ranges')
+ [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=('special:all transactions:(all)')
+ [[ -n "${package_commands[(r)$words[2]]}" ]] && alts+=("packages:packages:_yum_act_on_installed_pkgs")
+
+ (( ${+alts[1]} )) && _alternative "$alts[@]" || \
+ _message "unknown expansion for: yum history $words[2]"
+ fi
+ if (( CURRENT == 4 )); then
+ if [ "$words[2]" = "addon-info" ]; then
+ local -a historyargs
+ historyargs=(saved_tx)
+ _describe 'additional option' historyargs
+ fi
+ fi
+}
+
+
# Fills the all pkg cache
_yum_all_pkgs()
{
@@ -163,11 +275,34 @@ yum_repos() {
compadd "$@" -a -- enabled_yum_repos
}
+# Suggest installed packages
+_yum_act_on_installed_pkgs() {
+ _yum_installed_pkgs
+ compadd "$@" -a -- _installed_pkgs
+}
+
+# Completion function for distribution-synchronization|distro-sync
+(( $+functions[_yum_distribution-synchronization] )) || _yum_distribution-synchronization()
+{
+ _yum_act_on_installed_pkgs "$@"
+}
+
# Completion function for erase|remove
(( $+functions[_yum_erase] )) || _yum_erase()
{
- _yum_installed_pkgs
- compadd "$@" -a -- _installed_pkgs
+ _yum_act_on_installed_pkgs "$@"
+}
+
+# Completion function for downgrade
+(( $+functions[_yum_downgrade] )) || _yum_downgrade()
+{
+ _yum_act_on_installed_pkgs "$@"
+}
+
+# Completion function for reinstall
+(( $+functions[_yum_reinstall] )) || _yum_reinstall()
+{
+ _yum_act_on_installed_pkgs "$@"
}
# Completion function for install
@@ -191,6 +326,12 @@ yum_repos() {
return ret
}
+# Completion function for load-transaction
+(( $+functions[_yum_load-transaction] )) || _yum_load-transaction()
+{
+ _files
+}
+
# Completion function for localinstall
(( $+functions[_yum_localinstall] )) || _yum_localinstall()
{
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: PATCH Completion for _yum (contains FIXMEs)
2016-11-10 10:18 ` Paul Seyfert
@ 2016-11-10 15:49 ` Oliver Kiddle
2016-11-12 0:19 ` PATCH Completion for _yum Paul Seyfert
0 siblings, 1 reply; 19+ messages in thread
From: Oliver Kiddle @ 2016-11-10 15:49 UTC (permalink / raw)
To: Paul Seyfert; +Cc: zsh-workers
Paul Seyfert wrote:
>
> Now done as you suggest. Nice indeed (and I learned what the first
> packages in 'packages:packages:...' is good for).
The normal convention is for the descriptions to be in singular form. So
that would be 'packages:package:...'
Thanks for the update. I've got a few comments to add to what Daniel
already said.
+ "repolist:Display the configured software repositories"
+ "distribution-synchronization:Synchronize installed packages to the latest available versions"
+ "distro-sync:Synchronize installed packages to the latest available versions"
Another convention is lowercase for the descriptions, so "display",
"synchronize", etc.
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ local -a chkargs
+ #chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ #chkargs=("dependencies" "duplicates" "all") # according to help
+ chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ _describe -t arguments 'check arguments' chkargs
In quite a few cases, you're using _describe to add matches without
per-match descriptions. The whole point of _describe is to make it easy
to add matches that do have per-match descriptions. For this, you can
just use _wanted with compadd which is much more light-weight:
local expl
_wanted arguments expl 'check argument' compadd dependencies \
duplicates provides all
+ return 0
Completion functions should only return 0 if they added matches.
Otherwise, completion goes on and tries approximate completion and other
fallbacks you may have configured. Often you don't need a return
statement because if the last command is _wanted or _describe then its
return status will be passed on. In complex cases, start with local
ret=1, put && ret=0 after all commands that may add matches and finish
the function with return ret.
+_ids() {
It's probably unwise to define yum specific functions with generic names
like _ids and _ranges. A common convention would be _yum_ids with
_yum-check being for completion after "yum check".
+ # the last argument will be the first valid transaction ID to be suggested
+ # all other arguments are forwarded to compadd
+ #
+ # maxid is the last transaction ID known to yum
+ # minusone is the number of arguments provided to _ids minus one
+ local maxid
+ local minusone
+
+ maxid=$(yum history stats | grep Transactions | sed "s/.*: //")
+ ((minusone=$#-1))
+ compadd "${(@)@[1,$minusone]}" $(echo {$@[$#]..$maxid})
I'm getting some stderr output from yum history stats in my terminal
from this. I don't think you need the echo inside a subshell, the
brace-expansion alone should work.
+# Expand next argument after 'yum history'
+_yum_history() {
+ if (( CURRENT == 2 )); then
+ local -a historycommands
+ historycommands=('info' 'list' 'packages-list' 'packages-info' 'summary' 'addon-info' 'redo' 'undo' 'roll-back' 'new' 'sync' 'stats')
+ _describe -t commands 'yum history command' historycommands
+ fi
+ if (( CURRENT == 3 )); then
A minor point, but you can use elif here.
+ (( ${+alts[1]} )) && _alternative "$alts[@]" || \
+ _message "unknown expansion for: yum history $words[2]"
This will print the message in the case where _alternative is run but
there were no matches which I don't think is what you want. A full
if…then…else should be used.
And rather than printing a message, I think it is best to call _default
as the fallback so that the user gets filename completion. In the case
of a new subcommand being added in a new version of yum falling back to
default completion is more graceful.
Oliver
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: PATCH Completion for _yum
2016-11-10 15:49 ` Oliver Kiddle
@ 2016-11-12 0:19 ` Paul Seyfert
[not found] ` <31607.1478915523@hydra.kiddle.eu>
0 siblings, 1 reply; 19+ messages in thread
From: Paul Seyfert @ 2016-11-12 0:19 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 1031 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Hi,
Thanks for your input, updated versions attached.
I also noticed I forgot two $@ to forward -J and -X from _alternative
through _range to _ids.
Cheers,
Paul
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJYJmAWAAoJEPOmP9OjPXmr1fcP/1jtz2d0wPI7GFgkE1+ipTOR
1cfT1Rh6uWwpGWk01lmgy62lA/01Yo9lG+C+2xwgRktE/bw0S+ct+wlXcZ90JaGL
SLJiKRAHo3iO0Oad4HOxsqG4BdWzw4aN8ICfTuXe2Ub/hFJFOfjxZba7jVOkN5CS
rk54p3MTsMSIqmlxdVZRl33dQlKwazpisJsqTsyZa0YwSUtQR7t7cYG27eNNRkmA
qGAIBCTw6D3bp7EPfzpJ/FX5K+BSw19u4SCZLdjsdAmaBRsvcIwHbgDwRqJ206eY
jqtrMLcgNuQgxnGLPdK+qsgzK3hDHG0Ab6GT1ijbJlW6QbdG8Njzhb5PlwvRA9va
S6mWt6/tzf5MV1N6ttiRDmWJiFuyR12zASpj+e/mBq28om5LDbdtzBkSQBFEen0z
eqULgq2NDAx1Q+lvpjoYY8i+QrAxRkk4wuHg7sCJNfsrtpkSOmH29U1KO0wVYhMd
rIk33wSx+5Vy3AaRMJumnKV3wwJ8Ea9hTvaiQx13/yMbMUUpHny5coisY2yR47gH
UxSij89NmyJVlrg3j+v/X8xEpr/Cu1GKJFj66ldGDlRhHBOMCOyJ2vMp0UYnY/Uh
heye+hTDHSExuD17VMwwE5e7u526VFQVCCZgi1aKV10SDvJa3dlyLHKJq/6zbXoc
QD5nZTa/cGmu/FbD1LpK
=Z7CB
-----END PGP SIGNATURE-----
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: just_changes4.patch --]
[-- Type: text/x-patch; name="just_changes4.patch", Size: 6660 bytes --]
diff --git a/Completion/Redhat/Command/_yum b/Completion/Redhat/Command/_yum
index f453806..5919d4a 100644
--- a/Completion/Redhat/Command/_yum
+++ b/Completion/Redhat/Command/_yum
@@ -53,6 +53,18 @@ _yum()
"shell:enter the 'yum shell'"
"update:update one or more packages"
"upgrade:upgrade one or more packages"
+ "update-to:update one or more packages taking obsoletes into account"
+ "upgrade-to:upgrade one or more packages taking obsoletes into account"
+ "history:view past transactions"
+ "help:produce help for all or given command"
+ "load-transaction:load a saved transaction from a textfile"
+ "load-ts:load a saved transaction from a textfile"
+ "check:Check for problems in the rpmdb"
+ "reinstall:reinstall a package"
+ "downgrade:downgrade a package"
+ "repolist:display the configured software repositories"
+ "distribution-synchronization:synchronize installed packages to the latest available versions"
+ "distro-sync:synchronize installed packages to the latest available versions"
)
if (( CURRENT == 1 )); then
@@ -66,6 +78,10 @@ _yum()
remove) cmd="erase";;
whatprovides) cmd="provides";;
upgrade) cmd="update";;
+ upgrade-to) cmd="update";;
+ update-to) cmd="update";;
+ load-ts) cmd="load-transaction";;
+ distro-sync) cmd="distribution-synchronization";;
esac
if (( $#cmd )); then
@@ -77,7 +93,18 @@ _yum()
zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
fi
+ if [ "$cmd" = "help" ]; then
+ if (( CURRENT == 2 )); then
+ local -a _yum_cmd_names
+ _yum_cmd_names=(${_yum_cmds%%:*})
+ _describe -t commands 'commands' _yum_cmd_names
+ else
+ # help takes one argument
+ _message 'no more arguments'
+ fi
+ else
_call_function ret _yum_$cmd || _message 'no more arguments'
+ fi
else
_message "unknown yum command: $words[1]"
fi
@@ -85,6 +112,101 @@ _yum()
fi
}
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ ##chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ ##chkargs=("dependencies" "duplicates" "all") # according to help
+ #chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ local expl
+ _wanted arguments expl 'check argument' compadd dependencies \
+ duplicates provides all
+ else
+ return 1
+ fi
+}
+
+# Expand next argument after 'yum repolist'
+_yum_repolist() {
+ if (( CURRENT == 2 )); then
+ local expl
+ _wanted arguments expl 'repolist arguments' compadd all enabled disabled
+ else
+ return 1
+ fi
+}
+
+_yum_ids() {
+ # the last argument will be the first valid transaction ID to be suggested
+ # all other arguments are forwarded to compadd
+ #
+ # maxid is the last transaction ID known to yum
+ # minusone is the number of arguments provided to _yum_ids minus one
+ local maxid
+ local minusone
+
+ maxid=$(yum history stats | grep Transactions | sed "s/.*: //")
+
+ # `$#' is the number of arguments
+ ((minusone=$#-1))
+
+ # `$@' are the arguments
+ # `${(@)@[...]}' selects a subrange from $@
+ # `${(@)@[1,$minusone]}' are all except the last argument
+ # `$@[$#]' is the last argument, e.g. the first suggestable ID
+ compadd "${(@)@[1,$minusone]}" {$@[$#]..$maxid}
+}
+
+_yum_ranges() {
+ if compset -P '*..'; then
+ _yum_ids $@ ${(S)IPREFIX#..}
+ else
+ _yum_ids $@ -S '..' 1
+ fi
+}
+
+# Expand next argument after 'yum history'
+_yum_history() {
+ local expl
+ if (( CURRENT == 2 )); then
+ _wanted arguments expl "yum history command" compadd info list \
+ packages-list packages-info summary addon-info redo undo \
+ roll-back new sync stats
+ elif (( CURRENT == 3 )); then
+ local -a ID_commands
+ local -a ID_range_commands
+ local -a package_commands
+ local -a alts
+ alts=()
+ #ID_commands=('summary' 'info' 'list' 'stats' 'addon-info')
+ ID_commands=('addon-info')
+ ID_range_commands=('summary' 'info' 'list' 'stats')
+ package_commands=('summary' 'info' 'list' 'stats' 'packages-list' 'packages-info')
+ #package_commands=('packages-list' 'packages-info')
+ # packages-list, packages-info : needs package name
+ # summary, info, list, stats : ID, ID range, package name
+ # addon-info : ID
+ # redo, undo, roll-back, sync : unknown
+
+ [[ -n "${ID_commands[(r)$words[2]]}" ]] && alts+=('special:special ID:(last)')
+ [[ -n "${ID_commands[(r)$words[2]]}" ]] && alts+=('regular:ID:_yum_ids 1')
+ [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=('regular:transaction range:_yum_ranges')
+ [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=('special:all transactions:(all)')
+ [[ -n "${package_commands[(r)$words[2]]}" ]] && alts+=("package:package:_yum_act_on_installed_pkgs")
+
+ if (( ${+alts[1]} )) ; then
+ _alternative "$alts[@]"
+ else
+ _default
+ fi
+ elif (( CURRENT == 4 )); then
+ if [ "$words[2]" = "addon-info" ]; then
+ _wanted arguments expl 'additional option' compadd saved_tx
+ fi
+ fi
+}
+
+
# Fills the all pkg cache
_yum_all_pkgs()
{
@@ -163,11 +285,34 @@ yum_repos() {
compadd "$@" -a -- enabled_yum_repos
}
+# Suggest installed packages
+_yum_act_on_installed_pkgs() {
+ _yum_installed_pkgs
+ compadd "$@" -a -- _installed_pkgs
+}
+
+# Completion function for distribution-synchronization|distro-sync
+(( $+functions[_yum_distribution-synchronization] )) || _yum_distribution-synchronization()
+{
+ _yum_act_on_installed_pkgs "$@"
+}
+
# Completion function for erase|remove
(( $+functions[_yum_erase] )) || _yum_erase()
{
- _yum_installed_pkgs
- compadd "$@" -a -- _installed_pkgs
+ _yum_act_on_installed_pkgs "$@"
+}
+
+# Completion function for downgrade
+(( $+functions[_yum_downgrade] )) || _yum_downgrade()
+{
+ _yum_act_on_installed_pkgs "$@"
+}
+
+# Completion function for reinstall
+(( $+functions[_yum_reinstall] )) || _yum_reinstall()
+{
+ _yum_act_on_installed_pkgs "$@"
}
# Completion function for install
@@ -191,6 +336,12 @@ yum_repos() {
return ret
}
+# Completion function for load-transaction
+(( $+functions[_yum_load-transaction] )) || _yum_load-transaction()
+{
+ _files
+}
+
# Completion function for localinstall
(( $+functions[_yum_localinstall] )) || _yum_localinstall()
{
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-extend-yum-completion.patch --]
[-- Type: text/x-patch; name="0001-extend-yum-completion.patch", Size: 22487 bytes --]
From c99e182878d5f1da4a1add0983fb4532188606f6 Mon Sep 17 00:00:00 2001
From: Paul Seyfert <paul.seyfert@mib.infn.it>
Date: Sun, 23 Oct 2016 01:42:46 +0200
Subject: [PATCH] extend yum completion
adding the following yum commands:
* update-to (just what update expands)
* upgrade-to (just what update expands)
* history (the actual tricky one)
* help (printing the available commands)
* load-transaction (_files)
* load-ts (_files)
* check (just what the man page suggested)
* reinstall (just what erase does - suggest installed packages)
* downgrade (just what erase does - suggest installed packages)
* repolist (just what the man page suggested)
* distribution-synchronization (just what erase does - suggest installed packages)
* distro-sync (just what erase does - suggest installed packages)
A few history commands don't get expanded.
Taken from the man page of yum 3.2.29.
Reindented file.
---
Completion/Redhat/Command/_yum | 527 ++++++++++++++++++++++++++---------------
1 file changed, 339 insertions(+), 188 deletions(-)
diff --git a/Completion/Redhat/Command/_yum b/Completion/Redhat/Command/_yum
index f453806..be56813 100644
--- a/Completion/Redhat/Command/_yum
+++ b/Completion/Redhat/Command/_yum
@@ -3,293 +3,444 @@
# Main dispatcher
_yum()
{
- local curcontext="$curcontext" state lstate line
-
- _arguments -s \
- '(- *)'{-h,--help}'[show the help message]' \
- '(-t --tolerant)'{-t,--tolerant}'[be tolerant of errors]' \
- '(-C --cacheonly)'{-C,--cacheonly}'[run entirely from cache]' \
- '(-c --config)'{-c,--config=}'[config file location]:Yum conf file:_files' \
- '(-R --randomwait)'{-R,--randomwait=}'[maximum command wait time (in minutes)]:max wait time' \
- '(-d --debuglevel)'{-d,--debuglevel=}'[debug level (0-10)]:debug level' \
- '(-e --errorlevel)'{-e,--errorlevel=}'[error level (0-10)]:error level' \
- '(-y --assumeyes)'{-y,--assumeyes}'[answer yes for all questions]' \
- '--installroot=[set install root]:install root:_files -/' \
- '*--enablerepo=[enable or or more repositories]:repos to enable:_yum_disabled_repos_list' \
- '*--disablerepo=[disable one or more repositories]:disable repos:_yum_enabled_repos_list' \
- {*-x,*--exclude=}'[exclude package(s) by name or glob]:exclude packages' \
- '--version[show yum version]' \
- '--obsoletes[enable obsoletes processing during updates]' \
- '--nogpgcheck[disable gpg signature checking]' \
- '--noplugins[disable yum plugins]' \
- '--disablepresto[disable Presto plugin and don''''t download any deltarpms]' \
- '*::yum command:_yum_command'
+ local curcontext="$curcontext" state lstate line
+
+ _arguments -s \
+ '(- *)'{-h,--help}'[show the help message]' \
+ '(-t --tolerant)'{-t,--tolerant}'[be tolerant of errors]' \
+ '(-C --cacheonly)'{-C,--cacheonly}'[run entirely from cache]' \
+ '(-c --config)'{-c,--config=}'[config file location]:Yum conf file:_files' \
+ '(-R --randomwait)'{-R,--randomwait=}'[maximum command wait time (in minutes)]:max wait time' \
+ '(-d --debuglevel)'{-d,--debuglevel=}'[debug level (0-10)]:debug level' \
+ '(-e --errorlevel)'{-e,--errorlevel=}'[error level (0-10)]:error level' \
+ '(-y --assumeyes)'{-y,--assumeyes}'[answer yes for all questions]' \
+ '--installroot=[set install root]:install root:_files -/' \
+ '*--enablerepo=[enable or or more repositories]:repos to enable:_yum_disabled_repos_list' \
+ '*--disablerepo=[disable one or more repositories]:disable repos:_yum_enabled_repos_list' \
+ {*-x,*--exclude=}'[exclude package(s) by name or glob]:exclude packages' \
+ '--version[show yum version]' \
+ '--obsoletes[enable obsoletes processing during updates]' \
+ '--nogpgcheck[disable gpg signature checking]' \
+ '--noplugins[disable yum plugins]' \
+ '--disablepresto[disable Presto plugin and don''''t download any deltarpms]' \
+ '*::yum command:_yum_command'
}
(( $+functions[_yum_command] )) || _yum_command()
{
- local -a _yum_cmds
- _yum_cmds=(
- "install:install the latest version of a package or group of packages"
- "erase:remove an installed package (with its dependencies)"
- "remove:remove an installed package (with its dependencies)"
- "clean:clean local yum cache"
- "deplist:gives a list of all dependencies for a package"
- "check-update:check if any updates are available"
- "info:get description of available packages"
- "list:is used to list various information about packages"
- "groupinfo:get info on package groups"
- "groupinstall:install a package group or groups"
- "groupremove:remove a package group or groups"
- "grouplist:list package groups"
- "groupupdate:update a package group or groups"
- "localinstall:install packages with local rpm files"
- "localupdate:update packages with local rpm files"
- "makecache:makes a local yum cache"
- "provides:find out which package provides some feature or file"
- "whatprovides:find out which package provides some feature or file"
- "resolvedep:list packages providing the specified dependencies"
- "search:find any packages matching pattern"
- "shell:enter the 'yum shell'"
- "update:update one or more packages"
- "upgrade:upgrade one or more packages"
- )
-
- if (( CURRENT == 1 )); then
- _describe -t commands 'yum command' _yum_cmds || compadd "$@"
- else
- local curcontext="$curcontext"
-
- cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
- # Deal with any aliases
- case $cmd in
- remove) cmd="erase";;
- whatprovides) cmd="provides";;
- upgrade) cmd="update";;
- esac
-
- if (( $#cmd )); then
- curcontext="${curcontext%:*:*}:yum-${cmd}:"
-
- local update_policy
- zstyle -s ":completion:${curcontext}:" cache-policy update_policy
- if [[ -z "$update_policy" ]]; then
- zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
- fi
-
- _call_function ret _yum_$cmd || _message 'no more arguments'
- else
- _message "unknown yum command: $words[1]"
- fi
- return ret
- fi
+ local -a _yum_cmds
+ _yum_cmds=(
+ "install:install the latest version of a package or group of packages"
+ "erase:remove an installed package (with its dependencies)"
+ "remove:remove an installed package (with its dependencies)"
+ "clean:clean local yum cache"
+ "deplist:gives a list of all dependencies for a package"
+ "check-update:check if any updates are available"
+ "info:get description of available packages"
+ "list:is used to list various information about packages"
+ "groupinfo:get info on package groups"
+ "groupinstall:install a package group or groups"
+ "groupremove:remove a package group or groups"
+ "grouplist:list package groups"
+ "groupupdate:update a package group or groups"
+ "localinstall:install packages with local rpm files"
+ "localupdate:update packages with local rpm files"
+ "makecache:makes a local yum cache"
+ "provides:find out which package provides some feature or file"
+ "whatprovides:find out which package provides some feature or file"
+ "resolvedep:list packages providing the specified dependencies"
+ "search:find any packages matching pattern"
+ "shell:enter the 'yum shell'"
+ "update:update one or more packages"
+ "upgrade:upgrade one or more packages"
+ "update-to:update one or more packages taking obsoletes into account"
+ "upgrade-to:upgrade one or more packages taking obsoletes into account"
+ "history:view past transactions"
+ "help:produce help for all or given command"
+ "load-transaction:load a saved transaction from a textfile"
+ "load-ts:load a saved transaction from a textfile"
+ "check:Check for problems in the rpmdb"
+ "reinstall:reinstall a package"
+ "downgrade:downgrade a package"
+ "repolist:display the configured software repositories"
+ "distribution-synchronization:synchronize installed packages to the latest available versions"
+ "distro-sync:synchronize installed packages to the latest available versions"
+ )
+
+ if (( CURRENT == 1 )); then
+ _describe -t commands 'yum command' _yum_cmds || compadd "$@"
+ else
+ local curcontext="$curcontext"
+
+ cmd="${${_yum_cmds[(r)$words[1]:*]%%:*}}"
+ # Deal with any aliases
+ case $cmd in
+ remove) cmd="erase";;
+ whatprovides) cmd="provides";;
+ upgrade) cmd="update";;
+ upgrade-to) cmd="update";;
+ update-to) cmd="update";;
+ load-ts) cmd="load-transaction";;
+ distro-sync) cmd="distribution-synchronization";;
+ esac
+
+ if (( $#cmd )); then
+ curcontext="${curcontext%:*:*}:yum-${cmd}:"
+
+ local update_policy
+ zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+ if [[ -z "$update_policy" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy _yum_caching_policy
+ fi
+
+ if [ "$cmd" = "help" ]; then
+ if (( CURRENT == 2 )); then
+ local -a _yum_cmd_names
+ _yum_cmd_names=(${_yum_cmds%%:*})
+ _describe -t commands 'commands' _yum_cmd_names
+ else
+ # help takes one argument
+ _message 'no more arguments'
+ fi
+ else
+ _call_function ret _yum_$cmd || _message 'no more arguments'
+ fi
+ else
+ _message "unknown yum command: $words[1]"
+ fi
+ return ret
+ fi
+}
+
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ ##chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ ##chkargs=("dependencies" "duplicates" "all") # according to help
+ #chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ local expl
+ _wanted arguments expl 'check argument' compadd dependencies \
+ duplicates provides all
+ else
+ return 1
+ fi
+}
+
+# Expand next argument after 'yum repolist'
+_yum_repolist() {
+ if (( CURRENT == 2 )); then
+ local expl
+ _wanted arguments expl 'repolist arguments' compadd all enabled disabled
+ else
+ return 1
+ fi
+}
+
+_yum_ids() {
+ # the last argument will be the first valid transaction ID to be suggested
+ # all other arguments are forwarded to compadd
+ #
+ # maxid is the last transaction ID known to yum
+ # minusone is the number of arguments provided to _yum_ids minus one
+ local maxid
+ local minusone
+
+ maxid=$(yum history stats | grep Transactions | sed "s/.*: //")
+
+ # `$#' is the number of arguments
+ ((minusone=$#-1))
+
+ # `$@' are the arguments
+ # `${(@)@[...]}' selects a subrange from $@
+ # `${(@)@[1,$minusone]}' are all except the last argument
+ # `$@[$#]' is the last argument, e.g. the first suggestable ID
+ compadd "${(@)@[1,$minusone]}" {$@[$#]..$maxid}
}
+_yum_ranges() {
+ if compset -P '*..'; then
+ _yum_ids $@ ${(S)IPREFIX#..}
+ else
+ _yum_ids $@ -S '..' 1
+ fi
+}
+
+# Expand next argument after 'yum history'
+_yum_history() {
+ local expl
+ if (( CURRENT == 2 )); then
+ _wanted arguments expl "yum history command" compadd info list \
+ packages-list packages-info summary addon-info redo undo \
+ roll-back new sync stats
+ elif (( CURRENT == 3 )); then
+ local -a ID_commands
+ local -a ID_range_commands
+ local -a package_commands
+ local -a alts
+ alts=()
+ #ID_commands=('summary' 'info' 'list' 'stats' 'addon-info')
+ ID_commands=('addon-info')
+ ID_range_commands=('summary' 'info' 'list' 'stats')
+ package_commands=('summary' 'info' 'list' 'stats' 'packages-list' 'packages-info')
+ #package_commands=('packages-list' 'packages-info')
+ # packages-list, packages-info : needs package name
+ # summary, info, list, stats : ID, ID range, package name
+ # addon-info : ID
+ # redo, undo, roll-back, sync : unknown
+
+ [[ -n "${ID_commands[(r)$words[2]]}" ]] && alts+=('special:special ID:(last)')
+ [[ -n "${ID_commands[(r)$words[2]]}" ]] && alts+=('regular:ID:_yum_ids 1')
+ [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=('regular:transaction range:_yum_ranges')
+ [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=('special:all transactions:(all)')
+ [[ -n "${package_commands[(r)$words[2]]}" ]] && alts+=("package:package:_yum_act_on_installed_pkgs")
+
+ if (( ${+alts[1]} )) ; then
+ _alternative "$alts[@]"
+ else
+ _default
+ fi
+ elif (( CURRENT == 4 )); then
+ if [ "$words[2]" = "addon-info" ]; then
+ _wanted arguments expl 'additional option' compadd saved_tx
+ fi
+ fi
+}
+
+
# Fills the all pkg cache
_yum_all_pkgs()
{
- if ( [[ ${+_all_pkgs} -eq 0 ]] || _cache_invalid ALL ) &&
- ! _retrieve_cache ALL;
- then
- _all_pkgs=( $(yum -C list all | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache ALL _all_pkgs
- fi
+ if ( [[ ${+_all_pkgs} -eq 0 ]] || _cache_invalid ALL ) &&
+ ! _retrieve_cache ALL;
+then
+ _all_pkgs=( $(yum -C list all | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache ALL _all_pkgs
+fi
}
# Fills the installed pkg cache
_yum_installed_pkgs()
{
- if ( [[ ${+_installed_pkgs} -eq 0 ]] || _cache_invalid INSTALLED ) &&
- ! _retrieve_cache INSTALLED;
- then
- _installed_pkgs=( $(yum -C list installed | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache INSTALLED _installed_pkgs
- fi
+ if ( [[ ${+_installed_pkgs} -eq 0 ]] || _cache_invalid INSTALLED ) &&
+ ! _retrieve_cache INSTALLED;
+then
+ _installed_pkgs=( $(yum -C list installed | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache INSTALLED _installed_pkgs
+fi
}
# Fills the available pkg cache
_yum_available_pkgs()
{
- if ( [[ ${+_available_pkgs} -eq 0 ]] || _cache_invalid AVAILABLE ) &&
- ! _retrieve_cache AVAILABLE;
- then
- _available_pkgs=( $(yum -C list available | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache AVAILABLE _available_pkgs
- fi
+ if ( [[ ${+_available_pkgs} -eq 0 ]] || _cache_invalid AVAILABLE ) &&
+ ! _retrieve_cache AVAILABLE;
+then
+ _available_pkgs=( $(yum -C list available | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache AVAILABLE _available_pkgs
+fi
}
# Fills the upgrade pkg cache
_yum_upgrade_pkgs()
{
- if ( [[ ${+_upgrade_pkgs} -eq 0 ]] || _cache_invalid UPGRADE ) &&
- ! _retrieve_cache UPGRADE;
- then
- _upgrade_pkgs=( $(yum -C list upgrade | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
- _store_cache UPGRADE _upgrade_pkgs
- fi
+ if ( [[ ${+_upgrade_pkgs} -eq 0 ]] || _cache_invalid UPGRADE ) &&
+ ! _retrieve_cache UPGRADE;
+then
+ _upgrade_pkgs=( $(yum -C list upgrade | sed 's/\s.*//' | grep '\.' 2>/dev/null) )
+ _store_cache UPGRADE _upgrade_pkgs
+fi
}
# Gets the list of defined repos
yum_repos() {
- local trepo
- local -a tarray
- tarray=( $(egrep -h '(^\[.*\]|^enabled.*=)' /etc/yum.repos.d/*.repo /etc/yum.conf | sed -e 's/ //g' | sed -e 's/\[//g' | sed -e 's/\].*$//g' 2>/dev/null) )
- local -i eindex=0
- local -i dindex=0
- for line in $tarray; do
- if [[ "$line" = "enabled=1" ]]; then
- enabled_yum_repos=($enabled_yum_repos $trepo)
- elif [[ "$line" = "enabled=0" ]]; then
- disabled_yum_repos=($disabled_yum_repos $trepo)
- elif [[ "$line" != "main" ]]; then
- trepo=$line
- fi
- done
+ local trepo
+ local -a tarray
+ tarray=( $(egrep -h '(^\[.*\]|^enabled.*=)' /etc/yum.repos.d/*.repo /etc/yum.conf | sed -e 's/ //g' | sed -e 's/\[//g' | sed -e 's/\].*$//g' 2>/dev/null) )
+ local -i eindex=0
+ local -i dindex=0
+ for line in $tarray; do
+ if [[ "$line" = "enabled=1" ]]; then
+ enabled_yum_repos=($enabled_yum_repos $trepo)
+ elif [[ "$line" = "enabled=0" ]]; then
+ disabled_yum_repos=($disabled_yum_repos $trepo)
+ elif [[ "$line" != "main" ]]; then
+ trepo=$line
+ fi
+ done
}
(( $+functions[_yum_disabled_repos_list] )) || _yum_disabled_repos_list()
{
- compset -P '*,'
- compset -S ',*'
- yum_repos
- compadd "$@" -a -- disabled_yum_repos
+ compset -P '*,'
+ compset -S ',*'
+ yum_repos
+ compadd "$@" -a -- disabled_yum_repos
}
(( $+functions[_yum_enabled_repos_list] )) || _yum_enabled_repos_list()
{
- compset -P '*,'
- compset -S ',*'
- yum_repos
- compadd "$@" -a -- enabled_yum_repos
+ compset -P '*,'
+ compset -S ',*'
+ yum_repos
+ compadd "$@" -a -- enabled_yum_repos
+}
+
+# Suggest installed packages
+_yum_act_on_installed_pkgs() {
+ _yum_installed_pkgs
+ compadd "$@" -a -- _installed_pkgs
+}
+
+# Completion function for distribution-synchronization|distro-sync
+(( $+functions[_yum_distribution-synchronization] )) || _yum_distribution-synchronization()
+{
+ _yum_act_on_installed_pkgs "$@"
}
# Completion function for erase|remove
(( $+functions[_yum_erase] )) || _yum_erase()
{
- _yum_installed_pkgs
- compadd "$@" -a -- _installed_pkgs
+ _yum_act_on_installed_pkgs "$@"
+}
+
+# Completion function for downgrade
+(( $+functions[_yum_downgrade] )) || _yum_downgrade()
+{
+ _yum_act_on_installed_pkgs "$@"
+}
+
+# Completion function for reinstall
+(( $+functions[_yum_reinstall] )) || _yum_reinstall()
+{
+ _yum_act_on_installed_pkgs "$@"
}
# Completion function for install
(( $+functions[_yum_install] )) || _yum_install()
{
- if ! [[ $PREFIX == */* ]]; then
- _yum_available_pkgs
- fi
+ if ! [[ $PREFIX == */* ]]; then
+ _yum_available_pkgs
+ fi
- local ret=1
- _tags files packages
- while _tags; do
- if _requested files; then
- compadd "$@" -a -- _available_pkgs
- fi
- if _requested packages; then
- _call_function - _yum_localinstall
- fi
- (( ret )) || break
- done
- return ret
+ local ret=1
+ _tags files packages
+ while _tags; do
+ if _requested files; then
+ compadd "$@" -a -- _available_pkgs
+ fi
+ if _requested packages; then
+ _call_function - _yum_localinstall
+ fi
+ (( ret )) || break
+ done
+ return ret
+}
+
+# Completion function for load-transaction
+(( $+functions[_yum_load-transaction] )) || _yum_load-transaction()
+{
+ _files
}
# Completion function for localinstall
(( $+functions[_yum_localinstall] )) || _yum_localinstall()
{
- _files -/ -g '(#i)*.rpm(-.)'
+ _files -/ -g '(#i)*.rpm(-.)'
}
# Completion function for localupdate
(( $+functions[_yum_localupdate] )) || _yum_localupdate()
{
- _files -/ -g '(#i)*.rpm(-.)'
+ _files -/ -g '(#i)*.rpm(-.)'
}
# Completion function for update/upgrade
(( $+functions[_yum_update] )) || _yum_update()
{
- _yum_upgrade_pkgs
- compadd "$@" -a -- _upgrade_pkgs
+ _yum_upgrade_pkgs
+ compadd "$@" -a -- _upgrade_pkgs
}
# Completion function for deplist
(( $+functions[_yum_deplist] )) || _yum_deplist()
{
- _yum_available_pkgs
- compadd "$@" -a -- _available_pkgs
+ _yum_available_pkgs
+ compadd "$@" -a -- _available_pkgs
}
_yum_all()
{
- _yum_all_pkgs
- compadd "$@" -a -- _all_pkgs
+ _yum_all_pkgs
+ compadd "$@" -a -- _all_pkgs
}
_yum_list_or_info()
{
- local -a listlist
- listlist=(
- "all:all packages in repositories"
- "available:packages available in repositories"
- "updates:packages with updates available"
- "installed:installed packages"
- "extras:packages installed that are not available in any yum repository"
- "obsoletes:packages installed that are obsoleted"
- "recent:packages recently added to repositories"
- )
-
- if (( CURRENT == 2 )); then
- _describe -t yum-list-subcmds "Yum info/list sub-commands" listlist || _yum_all
- else
- local subcmd
- subcmd="${${listlist[(r)$words[2]:*]%%:*}}"
- # offer packages selected by the subcommand
- case $subcmd in
- all) _yum_all;;
- installed) _yum_erase;;
- available) _yum_install;;
- updates) _yum_update;;
- esac
- fi
+ local -a listlist
+ listlist=(
+ "all:all packages in repositories"
+ "available:packages available in repositories"
+ "updates:packages with updates available"
+ "installed:installed packages"
+ "extras:packages installed that are not available in any yum repository"
+ "obsoletes:packages installed that are obsoleted"
+ "recent:packages recently added to repositories"
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t yum-list-subcmds "Yum info/list sub-commands" listlist || _yum_all
+ else
+ local subcmd
+ subcmd="${${listlist[(r)$words[2]:*]%%:*}}"
+ # offer packages selected by the subcommand
+ case $subcmd in
+ all) _yum_all;;
+ installed) _yum_erase;;
+ available) _yum_install;;
+ updates) _yum_update;;
+ esac
+ fi
}
# Completion function for list
(( $+functions[_yum_list] )) || _yum_list()
{
- _yum_list_or_info
+ _yum_list_or_info
}
# Completion function for info
(( $+functions[_yum_info] )) || _yum_info()
{
- _yum_list_or_info
+ _yum_list_or_info
}
# Completion function for provides|whatprovides
(( $+functions[_yum_provides] )) || _yum_provides()
{
- _files
+ _files
}
# Completion function for resolvedep
(( $+functions[_yum_resolvedep] )) || _yum_resolvedep()
{
- _files
+ _files
}
# Completion function for clean
(( $+functions[_yum_clean] )) || _yum_clean()
{
- local -a cleanlist
- cleanlist=(
- "all:all cache"
- "cache:all cache"
- "dbcache:DB cache"
- "headers:cache headers"
- "packages:cache packages"
- "metadata:cache meta-data"
- )
-
- if (( CURRENT == 2 )); then
- _describe -t yum-clean-subcmds "Yum clean sub-commands" cleanlist
- fi
+ local -a cleanlist
+ cleanlist=(
+ "all:all cache"
+ "cache:all cache"
+ "dbcache:DB cache"
+ "headers:cache headers"
+ "packages:cache packages"
+ "metadata:cache meta-data"
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t yum-clean-subcmds "Yum clean sub-commands" cleanlist
+ fi
}
_yum_caching_policy()
--
2.1.4
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2016-12-15 17:15 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-26 17:37 PATCH Completion for _yum (contains FIXMEs) Paul Seyfert
2016-10-27 1:30 ` Daniel Shahaf
2016-10-31 12:09 ` Paul Seyfert
2016-11-10 10:18 ` Paul Seyfert
2016-11-10 15:49 ` Oliver Kiddle
2016-11-12 0:19 ` PATCH Completion for _yum Paul Seyfert
[not found] ` <31607.1478915523@hydra.kiddle.eu>
2016-11-22 19:05 ` caching mechanism and " Oliver Kiddle
2016-12-13 10:10 ` Oliver Kiddle
2016-12-13 16:18 ` Jun T.
2016-12-13 17:21 ` Bart Schaefer
2016-12-14 11:38 ` Oliver Kiddle
2016-12-14 14:23 ` Jun T.
2016-12-14 15:03 ` Oliver Kiddle
2016-12-14 15:23 ` Jun T.
2016-12-14 17:46 ` Oliver Kiddle
2016-12-14 20:09 ` Bart Schaefer
2016-12-15 9:38 ` Peter Stephenson
2016-12-15 17:15 ` Before 5.3.1 (was Re: caching mechanism and Re: PATCH Completion for _yum) Bart Schaefer
2016-12-13 16:38 ` caching mechanism and Re: PATCH Completion for _yum Bart Schaefer
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).