From d5ca0392786de1495bb3219bec19ca3887a678a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Sat, 13 Jun 2020 18:45:12 -0300 Subject: [PATCH] common/environment/setup/install.sh: add vcompletion. Install function for installing shell completions in the appropriate place according to the shell used. --- Manual.md | 7 +++++++ common/environment/setup/install.sh | 30 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Manual.md b/Manual.md index 5b49dc5ddd4..a2e43334b9d 100644 --- a/Manual.md +++ b/Manual.md @@ -337,6 +337,13 @@ The following functions are defined by `xbps-src` and can be used on any templat Note that vsed will call the sed command for every regex specified against every file specified, in the order that they are given. +- *vcompletion()* ` []` + + Installs shell completion from `file` for `command`, in the correct location + and with the appropriate filename for `shell`. If `command` isn't specified, + it will default to `pkgname`. The `shell` argument can be one of `bash`, + `fish` or `zsh`. + > Shell wildcards must be properly quoted, Example: `vmove "usr/lib/*.a"`. diff --git a/common/environment/setup/install.sh b/common/environment/setup/install.sh index f9a1ace90e7..742f13075f8 100644 --- a/common/environment/setup/install.sh +++ b/common/environment/setup/install.sh @@ -13,7 +13,7 @@ _noglob_helper() { } # Apply _noglob to v* commands -for cmd in vinstall vcopy vmove vmkdir vbin vman vdoc vconf vsconf vlicense vsv; do +for cmd in vinstall vcopy vcompletion vmove vmkdir vbin vman vdoc vconf vsconf vlicense vsv; do alias ${cmd}="set -f; _noglob_helper _${cmd}" done @@ -258,3 +258,31 @@ _vmkdir() { install -dm${mode} ${_destdir}/${dir} fi } + +_vcompletion() { + local file="$1" shell="$2" cmd="${3:-${pkgname}}" + local _bash_completion_dir=usr/share/bash-completion/completions/ + local _fish_completion_dir=usr/share/fish/vendor_completions.d/ + local _zsh_completion_dir=usr/share/zsh/site-functions/ + + if [ -z "$DESTDIR" ]; then + msg_red "$pkgver: vcompletion: DESTDIR unset, can't continue...\n" + return 1 + fi + + if [ $# -lt 2 ]; then + msg_red "$pkgver: vcompletion: 2 arguments expected: \n" + return 1 + fi + + if ! [ -f "$file" ]; then + msg_red "$pkgver: vcompletion: file $file doesn't exist\n" + fi + + case "$shell" in + bash) vinstall "$file" 0644 $_bash_completion_dir "${cmd}" ;; + fish) vinstall "$file" 0644 $_fish_completion_dir "${cmd}.fish" ;; + zsh) vinstall "$file" 0644 $_zsh_completion_dir "_${cmd}" ;; + *) msg_red "$pkgver: vcompletion: unknown shell ${shell}" ;; + esac +}