From d5826968b713123a4f51d3dec1adb1225d0e194f Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 2 May 2019 16:14:46 -0300 Subject: [PATCH] abuild.in: add default bashcomp, zshcomp and fishcomp functions --- abuild.in | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/abuild.in b/abuild.in index c79596b..cb2309c 100644 --- a/abuild.in +++ b/abuild.in @@ -552,12 +552,23 @@ subpkg_set() { [ "$_splitarch" = "$1" ] && _splitarch="" subpkgsplit=${_splitarch%%:*} - [ -z "$subpkgsplit" ] && subpkgsplit="${subpkgname##*-}" + + if [ -z "$subpkgsplit" ]; then + if is_bashcomp_pkg "$subpkgname"; then + subpkgsplit=bashcomp + elif is_zshcomp_pkg "$subpkgname"; then + subpkgsplit=zshcomp + elif is_fishcomp_pkg "$subpkgname"; then + subpkgsplit=fishcomp + else + subpkgsplit="${subpkgname##*-}" + fi + fi subpkgarch=${_splitarch#*:} if [ "$subpkgarch" = "$_splitarch" -o -z "$subpkgarch" ]; then case "$subpkgname" in - *-doc | *-openrc | *-lang | *-lang-*) subpkgarch="noarch" ;; + *-doc | *-openrc | *-lang | *-lang-* | *sh-completion) subpkgarch="noarch" ;; *) subpkgarch="$pkgarch" ;; esac fi @@ -1181,6 +1192,21 @@ is_openrc_pkg() { test "${1%-openrc}" != "$1" } +# returns true if this is the -bash-completion package +is_bashcomp_pkg() { + test "${1%-bash-completion}" != "$1" +} + +# returns true if this is the -zsh-completion package +is_zshcomp_pkg() { + test "${1%-zsh-completion}" != "$1" +} + +# returns true if this is the -fish-completion package +is_fishcomp_pkg() { + test "${1%-fish-completion}" != "$1" +} + # check that noarch is set if needed archcheck() { options_has "!archcheck" && return 0 @@ -1880,6 +1906,43 @@ openrc() { default_openrc } +default_bashcomp() { + depends="" + pkgdesc="Bash completions for $pkgname" + install_if="$pkgname=$pkgver-r$pkgrel bash-completion" + + cd "$pkgdir" || return 0 + amove /usr/share/bash-completion/completions +} + +bashcomp() { + default_bashcomp +} + +default_zshcomp() { + depends="" + pkgdesc="Zsh completions for $pkgname" + install_if="$pkgname=$pkgver-r$pkgrel zsh" + + amove usr/share/zsh/site-functions +} + +zshcomp() { + default_zshcomp +} + +default_fishcomp() { + depends="" + pkgdesc="Fish completions for $pkgname" + install_if="$pkgname=$pkgver-r$pkgrel fish" + + cd "$pkgdir" || return 0 + amove usr/share/fish/completions +} + +fishcomp() { + default_fishcomp +} is_function() { type "$1" 2>&1 | head -n 1 | egrep -q "is a (shell )?function"