Skip to content

Commit

Permalink
Merge pull request #1051 from akinomyoga/refactor-api-8
Browse files Browse the repository at this point in the history
refactor(completions/*): apply API renaming
  • Loading branch information
akinomyoga authored Nov 18, 2023
2 parents 11cc3bb + 3c7fe7b commit 3fbf99e
Show file tree
Hide file tree
Showing 32 changed files with 264 additions and 276 deletions.
2 changes: 1 addition & 1 deletion completions/_svn
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _comp_cmd_svn()
return
;;
--encoding)
_comp_xfunc iconv charsets
_comp_compgen -x iconv charsets
return
;;
--editor-cmd | --diff-cmd | --diff3-cmd)
Expand Down
29 changes: 16 additions & 13 deletions completions/_yum
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ _comp_cmd_yum__list()
fi
}

# TODO:API: rename per conventions, rework to use vars rather than outputting
_yum_repolist()
_comp_cmd_yum__compgen_repolist()
{
# -d 0 causes repolist to output nothing as of yum 3.2.22:
# http://yum.baseurl.org/ticket/83
# Drop first ("repo id repo name") and last ("repolist: ...") rows
yum --noplugins -C repolist "$1" 2>/dev/null |
command sed -ne '/^repo\s\s*id/d' -e '/^repolist:/d' \
-e 's/[[:space:]].*//p'
_comp_compgen_split -- "$(
yum --noplugins -C repolist "$1" 2>/dev/null |
command sed -ne '/^repo\s\s*id/d' -e '/^repolist:/d' \
-e 's/[[:space:]].*//p'
)"
}

# TODO:API: rename per conventions, rework to use vars rather than outputting
_yum_plugins()
_comp_cmd_yum__compgen_plugins()
{
local -a files
_comp_expand_glob files '/usr/lib/yum-plugins/*.py{,c,o}'
((${#files[@]})) &&
((${#files[@]})) || return
_comp_compgen -U files split -- "$(
printf '%s\n' "${files[@]}" |
command sed -ne 's|.*/\([^./]*\)\.py[co]\{0,1\}$|\1|p' | sort -u
command sed -ne 's|.*/\([^./]*\)\.py[co]\{0,1\}$|\1|p' | sort -u
)"
}

_comp_cmd_yum()
Expand Down Expand Up @@ -105,16 +107,17 @@ _comp_cmd_yum()
_comp_compgen_filedir -d
;;
--enablerepo)
_comp_compgen_split -- "$(_yum_repolist disabled)"
_comp_cmd_yum__compgen_repolist disabled
;;
--disablerepo)
_comp_compgen_split -- "$(_yum_repolist enabled)"
_comp_cmd_yum__compgen_repolist enabled
;;
--disableexcludes)
_comp_compgen_split -- "$(_yum_repolist all) all main"
_comp_cmd_yum__compgen_repolist all
_comp_compgen -a -- -W "all main"
;;
--enableplugin | --disableplugin)
_comp_compgen_split -- "$(_yum_plugins)"
_comp_cmd_yum__compgen_plugins
;;
--color)
_comp_compgen -- -W 'always auto never'
Expand Down
2 changes: 1 addition & 1 deletion completions/a2x
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _comp_cmd_a2x()
return
;;
--doctype | -${noargopts}d)
_comp_xfunc asciidoc doctype
_comp_compgen -x asciidoc doctype
return
;;
--stylesheet)
Expand Down
4 changes: 2 additions & 2 deletions completions/apt-build
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ _comp_cmd_apt_build()
if [[ $special ]]; then
case $special in
install | source | info)
COMPREPLY=($(_comp_xfunc apt-cache packages))
_comp_compgen -x apt-cache packages
;;
remove)
_comp_xfunc dpkg installed_packages
_comp_compgen -x dpkg installed_packages
;;
esac
return
Expand Down
65 changes: 37 additions & 28 deletions completions/apt-cache
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
# Debian apt-cache(8) completion -*- shell-script -*-

# List APT binary packages
# TODO:API: make it a generator
# @since 2.12
_comp_xfunc_apt_cache_packages()
_comp_xfunc_apt_cache_compgen_packages()
{
_comp_cmd_apt_cache__packages apt-cache
_comp_cmd_apt_cache__compgen_packages apt-cache
}

# TODO:API: make it a generator
_comp_cmd_apt_cache__packages()
# List APT binary packages
# @param $1 Name of executable
_comp_cmd_apt_cache__compgen_packages()
{
"$1" --no-generate pkgnames "$cur" 2>/dev/null || :
_comp_compgen_split -- "$("$1" --no-generate pkgnames "$cur" 2>/dev/null)"
}

# List APT source packages
# TODO:API: make it a generator
# @since 2.12
_comp_xfunc_apt_cache_sources()
_comp_xfunc_apt_cache_compgen_sources()
{
_comp_cmd_apt_cache__compgen_sources apt-cache
}

# List APT source packages
# @param $1 Name of executable
_comp_cmd_apt_cache__compgen_sources()
{
_comp_cmd_apt_cache__sources apt-cache "$1"
_comp_compgen_split -- "$("$1" dumpavail |
awk '$1 == "Source:" { print $2 }' | sort -u)"
}

# TODO:API: make it a generator
_comp_cmd_apt_cache__sources()
# List APT binary packages
# @deprecated 2.12
_apt_cache_packages()
{
local ret
_comp_compgen -c "$2" -v ret split -- "$("$1" dumpavail |
awk '$1 == "Source:" { print $2 }' | sort -u)" &&
printf '%s\n' "${ret[@]}"
local packages
_comp_compgen -v packages -i apt-cache packages apt-cache &&
printf '%s\n' "${packages[@]}"
}

# List APT source packages
# TODO:API: make it a generator
# @since 2.12
_comp_xfunc_apt_cache_src_packages()
# @deprecated 2.12
_apt_cache_sources()
{
local ret
_comp_compgen -v ret split -- \
"$(_comp_cmd_apt_cache__sources apt-cache "$cur")" &&
printf '%s\n' "${ret[@]}"
local sources
_comp_compgen -v sources -c "$1" -i apt-cache sources apt-cache &&
printf '%s\n' "${sources[@]}"
}

_comp_deprecate_func 2.12 _apt_cache_packages _comp_xfunc_apt_cache_packages
_comp_deprecate_func 2.12 _apt_cache_sources _comp_xfunc_apt_cache_sources
_comp_deprecate_func 2.12 _apt_cache_src_packages \
_comp_xfunc_apt_cache_src_packages
# List APT source packages
# @deprecated 2.12
_apt_cache_src_packages()
{
local sources
_comp_compgen -v sources -i apt-cache sources apt-cache &&
printf '%s\n' "${sources[@]}"
}

_comp_cmd_apt_cache()
{
Expand All @@ -69,11 +78,11 @@ _comp_cmd_apt_cache()
;;

showsrc)
COMPREPLY=($(_comp_cmd_apt_cache__sources "$1" "$cur"))
_comp_cmd_apt_cache__compgen_sources "$1"
;;

*)
COMPREPLY=($(_comp_cmd_apt_cache__packages "$1"))
_comp_cmd_apt_cache__compgen_packages "$1"
;;

esac
Expand Down
16 changes: 6 additions & 10 deletions completions/apt-get
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# Debian apt-get(8) completion -*- shell-script -*-

# @since 2.12
# TODO:API: make it a generator
_comp_xfunc_apt_get_installed_packages()
_comp_xfunc_apt_get_compgen_installed_packages()
{
if [[ -f /etc/debian_version ]]; then
# Debian system
_comp_xfunc dpkg installed_packages
_comp_compgen -x dpkg installed_packages
else
# assume RPM based
_comp_xfunc rpm installed_packages
_comp_compgen -x rpm installed_packages
fi
}

_comp_deprecate_func 2.12 _comp_cmd_apt_get_installed_packages \
_comp_xfunc_apt_get_installed_packages

_comp_cmd_apt_get()
{
local cur prev words cword comp_args package
Expand All @@ -32,13 +28,13 @@ _comp_cmd_apt_get()
if [[ $special ]]; then
case $special in
remove | auto?(-)remove | purge)
_comp_xfunc_apt_get_installed_packages
_comp_xfunc_apt_get_compgen_installed_packages
;;
source)
# Prefer `apt-cache` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
COMPREPLY=($(_comp_xfunc apt-cache packages))
_comp_compgen -x apt-cache packages
_comp_compgen -a split -- "$(apt-cache dumpavail |
awk '$1 == "Source:" { print $2 }' | sort -u)"
;;
Expand All @@ -64,7 +60,7 @@ _comp_cmd_apt_get()
_comp_looks_like_path "$cur" && return
;;&
*)
COMPREPLY+=($(_comp_xfunc apt-cache packages))
_comp_compgen -ax apt-cache packages
;;
esac
return
Expand Down
2 changes: 1 addition & 1 deletion completions/apt-mark
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _comp_cmd_apt_mark()
return
;;
*)
_comp_xfunc apt-get installed_packages
_comp_compgen -x apt-get installed_packages
;;
esac
return
Expand Down
6 changes: 3 additions & 3 deletions completions/aptitude
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ _comp_cmd_aptitude()
install | hold | markauto | unmarkauto | dist-upgrade | full-upgrade | \
safe-upgrade | download | show | changelog | why | why-not | build-dep | \
add-user-tag | remove-user-tag | versions)
COMPREPLY=($(_comp_xfunc apt-cache packages))
_comp_compgen -x apt-cache packages
return
;;
purge | remove | reinstall | forbid-version)
_comp_xfunc dpkg installed_packages
_comp_compgen -x dpkg installed_packages
return
;;
unhold)
_comp_xfunc dpkg held_packages
_comp_compgen -x dpkg held_packages
return
;;
esac
Expand Down
13 changes: 8 additions & 5 deletions completions/asciidoc
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# asciidoc(1) completion -*- shell-script -*-

# @since 2.12
# TODO:API: make it a default, replace by default
_comp_xfunc_asciidoc_doctype()
_comp_xfunc_asciidoc_compgen_doctype()
{
_comp_compgen -a -- -W 'article book manpage'
_comp_compgen -- -W 'article book manpage'
}

_comp_deprecate_func 2.12 _asciidoc_doctype _comp_xfunc_asciidoc_doctype
# @deprecated 2.12
_asciidoc_doctype()
{
_comp_compgen -ax asciidoc doctype
}

_comp_cmd_asciidoc()
{
Expand All @@ -29,7 +32,7 @@ _comp_cmd_asciidoc()
return
;;
--doctype | -${noargopts}d)
_comp_xfunc_asciidoc_doctype
_comp_xfunc_asciidoc_compgen_doctype
return
;;
--help | -${noargopts}h)
Expand Down
16 changes: 9 additions & 7 deletions completions/bts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ _comp_cmd_bts__compgen_cached_bugs()
# Generate APT source packages prefixed with "src:"
_comp_cmd_bts__compgen_src_packages_with_prefix()
{
local ppn=${cur:4} # partial package name, after stripping "src:"
_comp_compgen -c "$ppn" -U ppn split -P "src:" -- \
"$(_comp_xfunc apt-cache sources "$ppn")"
local _ppn=${cur:4} # partial package name, after stripping "src:"
local sources
_comp_compgen -v sources -c "$_ppn" -x apt-cache sources &&
_comp_compgen -U sources -- -P "src:" -W '"${sources[@]}"'
}

_comp_cmd_bts()
Expand Down Expand Up @@ -62,17 +63,17 @@ _comp_cmd_bts()
return
;;
package)
COMPREPLY=($(_comp_xfunc apt-cache packages))
_comp_compgen -x apt-cache packages
return
;;
cache)
COMPREPLY=($(_comp_xfunc apt-cache packages))
_comp_compgen -x apt-cache packages
_comp_compgen -ai bts src_packages_with_prefix
_comp_compgen -a -- -W 'from: release-critical RC'
return
;;
cleancache)
COMPREPLY=($(_comp_xfunc apt-cache packages))
_comp_compgen -x apt-cache packages
_comp_compgen -ai bts src_packages_with_prefix
_comp_compgen -a -- -W 'from: tag: usertag: ALL'
return
Expand All @@ -86,7 +87,8 @@ _comp_cmd_bts()
# COMP_WORDS would be: "bts cleancache src : <partial_pkg_name>"
pos=$((COMP_CWORD - 2))
if [[ $pos -gt 0 && ${COMP_WORDS[pos]} == "src" ]]; then
COMPREPLY=($(_comp_xfunc apt-cache src_packages))
_comp_compgen -x apt-cache sources

return
fi
;;
Expand Down
Loading

0 comments on commit 3fbf99e

Please sign in to comment.