shell-completion.eclass: include functions of bash-completion-r1.eclass

Include the functions of bash-completion-r1.eclass instead of
inheriting bash-completion-r1.eclass. The idea is to phase out
bash-completion-r1.eclass in favor of shell-completion.eclass with
EAPI 9.

Signed-off-by: Florian Schmaus <flow@gentoo.org>
Part-of: https://github.com/gentoo/gentoo/pull/46458
This commit is contained in:
Florian Schmaus
2026-06-22 19:34:40 +02:00
parent c887a67b78
commit 016b49f445

View File

@@ -1,14 +1,14 @@
# Copyright 2023-2024 Gentoo Authors
# Copyright 2023-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: shell-completion.eclass
# @MAINTAINER:
# Jonas Frei <freijon@pm.me>
# Florian Schmaus <flow@gentoo.org>
# mgorny@gentoo.org
# @AUTHOR:
# Alfred Wingate <parona@protonmail.com>
# @SUPPORTED_EAPIS: 8
# @PROVIDES: bash-completion-r1
# @BLURB: a few quick functions to install various shell completion files
# @DESCRIPTION:
# This eclass provides a standardised way to install shell completions
@@ -23,8 +23,114 @@ esac
if [[ -z ${_SHELL_COMPLETION_ECLASS} ]]; then
_SHELL_COMPLETION_ECLASS=1
# Extend bash-completion-r1
inherit bash-completion-r1
inherit toolchain-funcs
# @FUNCTION: _bash-completion-r1_get_bashdir
# @INTERNAL
# @DESCRIPTION:
# First argument is name of the string in bash-completion.pc
# Second argument is the fallback directory if the string is not found
# @EXAMPLE:
# _bash-completion-r1_get_bashdir completionsdir /usr/share/bash-completion
_bash-completion-r1_get_bashdir() {
debug-print-function ${FUNCNAME} "$@"
if $(tc-getPKG_CONFIG) --exists bash-completion &>/dev/null; then
local path
path=$($(tc-getPKG_CONFIG) --variable="${1}" bash-completion) || die
# we need to return unprefixed, so strip from what pkg-config returns
# to us, bug #477692
echo "${path#"${EPREFIX}"}"
else
echo "${2}"
fi
}
# @FUNCTION: _bash-completion-r1_get_bashcompdir
# @INTERNAL
# @DESCRIPTION:
# Get unprefixed bash-completion completions directory.
_bash-completion-r1_get_bashcompdir() {
debug-print-function ${FUNCNAME} "$@"
_bash-completion-r1_get_bashdir completionsdir /usr/share/bash-completion/completions
}
# @FUNCTION: _bash-completion-r1_get_bashhelpersdir
# @INTERNAL
# @DESCRIPTION:
# Get unprefixed bash-completion helpers directory.
_bash-completion-r1_get_bashhelpersdir() {
debug-print-function ${FUNCNAME} "$@"
_bash-completion-r1_get_bashdir helpersdir /usr/share/bash-completion/helpers
}
# @FUNCTION: get_bashcompdir
# @DESCRIPTION:
# Get the bash-completion completions directory.
get_bashcompdir() {
debug-print-function ${FUNCNAME} "$@"
echo "${EPREFIX}$(_bash-completion-r1_get_bashcompdir)"
}
# @FUNCTION: get_bashhelpersdir
# @INTERNAL
# @DESCRIPTION:
# Get the bash-completion helpers directory.
get_bashhelpersdir() {
debug-print-function ${FUNCNAME} "$@"
echo "${EPREFIX}$(_bash-completion-r1_get_bashhelpersdir)"
}
# @FUNCTION: dobashcomp
# @USAGE: <file> [...]
# @DESCRIPTION:
# Install bash-completion files passed as args. Has EAPI-dependent failure
# behavior (like doins).
dobashcomp() {
debug-print-function ${FUNCNAME} "$@"
(
insopts -m 0644
insinto "$(_bash-completion-r1_get_bashcompdir)"
doins "${@}"
)
}
# @FUNCTION: newbashcomp
# @USAGE: <file> <newname>
# @DESCRIPTION:
# Install bash-completion file under a new name. Has EAPI-dependent failure
# behavior (like newins).
newbashcomp() {
debug-print-function ${FUNCNAME} "$@"
(
insopts -m 0644
insinto "$(_bash-completion-r1_get_bashcompdir)"
newins "${@}"
)
}
# @FUNCTION: bashcomp_alias
# @USAGE: <basename> <alias>...
# @DESCRIPTION:
# Alias <basename> completion to one or more commands (<alias>es).
bashcomp_alias() {
debug-print-function ${FUNCNAME} "$@"
[[ ${#} -lt 2 ]] && die "Usage: ${FUNCNAME} <basename> <alias>..."
local base=${1} f
shift
for f; do
dosym "${base}" "$(_bash-completion-r1_get_bashcompdir)/${f}" \
|| return
done
}
# @FUNCTION: _shell-completion_get_fishcompdir
# @INTERNAL