From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id DA91815802F for ; Fri, 31 Mar 2023 18:14:20 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1D77AE077D; Fri, 31 Mar 2023 18:14:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DB733E077D for ; Fri, 31 Mar 2023 18:14:19 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EDE02340FA3 for ; Fri, 31 Mar 2023 18:14:18 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6A9C5A0E for ; Fri, 31 Mar 2023 18:14:17 +0000 (UTC) From: "Jonas Frei" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Jonas Frei" Message-ID: <1680286383.e8b38584b1308aa123c3b60278d0f683f2331628.freijon@gentoo> Subject: [gentoo-commits] repo/proj/guru:dev commit in: eclass/ X-VCS-Repository: repo/proj/guru X-VCS-Files: eclass/shell-completion.eclass X-VCS-Directories: eclass/ X-VCS-Committer: freijon X-VCS-Committer-Name: Jonas Frei X-VCS-Revision: e8b38584b1308aa123c3b60278d0f683f2331628 X-VCS-Branch: dev Date: Fri, 31 Mar 2023 18:14:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 5f4d73c3-566b-4940-bd90-a7c250ccfd5a X-Archives-Hash: c47b51dfd60310abb93705d5a6f48778 commit: e8b38584b1308aa123c3b60278d0f683f2331628 Author: Jonas Frei pm me> AuthorDate: Fri Mar 31 18:13:03 2023 +0000 Commit: Jonas Frei pm me> CommitDate: Fri Mar 31 18:13:03 2023 +0000 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=e8b38584 shell-completion.eclass: New eclass Signed-off-by: Jonas Frei pm.me> eclass/shell-completion.eclass | 119 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/eclass/shell-completion.eclass b/eclass/shell-completion.eclass new file mode 100644 index 000000000..271378c51 --- /dev/null +++ b/eclass/shell-completion.eclass @@ -0,0 +1,119 @@ +# Copyright 2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: shell-completion.eclass +# @SUPPORTED_EAPIS: 6 7 8 +# @MAINTAINER: +# Jonas Frei +# @BLURB: A few quick functions to install various shell completion files +# @DESCRIPTION: +# This eclass provides a standardised way to install shell completions +# for popular shells. It inherits the already widely adopted +# `bash-completion-r1`, thus extending on its functionality. + +if [[ ! ${_SHELL_COMPLETION_ECLASS} ]]; then +_SHELL_COMPLETION_ECLASS=1 + +# Extend bash-completion-r1 +inherit bash-completion-r1 + +case ${EAPI} in + 6|7|8) ;; + *) die "${ECLASS}: EAPI ${EAPI} unsupported." +esac + +# @FUNCTION: _shell-completion_get_fishcompdir +# @INTERNAL +# @DESCRIPTION: +# Get unprefixed fish completions directory +_shell-completion_get_fishcompdir() { + debug-print-function ${FUNCNAME} "${@}" + + echo "/usr/share/fish/vendor_completions.d" +} + +# @FUNCTION: _shell-completion_get_zshcompdir +# @INTERNAL +# @DESCRIPTION: +# Get unprefixed zsh completions directory +_shell-completion_get_zshcompdir() { + debug-print-function ${FUNCNAME} "${@}" + + echo "/usr/share/zsh/site-functions" +} + +# @FUNCTION: get_fishcompdir +# @DESCRIPTION: +# Get the fish completions directory. +get_fishcompdir() { + debug-print-function ${FUNCNAME} "${@}" + + echo "${EPREFIX}$(_get_fishcompdir)" +} + +# @FUNCTION: get_zshcompdir +# @DESCRIPTION: +# Get the zsh completions directory. +get_zshcompdir() { + debug-print-function ${FUNCNAME} "${@}" + + echo "${EPREFIX}$(_get_zshcompdir)" +} + +# @FUNCTION: dofishcomp +# @USAGE: [...] +# @DESCRIPTION: +# Install fish completion files passed as args. +dofishcomp() { + debug-print-function ${FUNCNAME} "${@}" + + ( + insopts -m 0644 + insinto "$(_shell-completion_get_fishcompdir)" + doins "${@}" + ) +} + +# @FUNCTION: dozshcomp +# @USAGE: [...] +# @DESCRIPTION: +# Install zsh completion files passed as args. +dozshcomp() { + debug-print-function ${FUNCNAME} "${@}" + + ( + insopts -m 0644 + insinto "$(_shell-completion_get_zshcompdir)" + doins "${@}" + ) +} + +# @FUNCTION: newfishcomp +# @USAGE: +# @DESCRIPTION: +# Install fish file under a new name. +newfishcomp() { + debug-print-function ${FUNCNAME} "${@}" + + ( + insopts -m 0644 + insinto "$(_shell-completion_get_fishcompdir)" + newins "${@}" + ) +} + +# @FUNCTION: newzshcomp +# @USAGE: +# @DESCRIPTION: +# Install zsh file under a new name. +newzshcomp() { + debug-print-function ${FUNCNAME} "${@}" + + ( + insopts -m 0644 + insinto "$(_shell-completion_get_zshcompdir)" + newins "${@}" + ) +} + +fi