diff options
| author | 2020-06-13 18:45:12 -0300 | |
|---|---|---|
| committer | 2020-07-28 04:24:40 +0000 | |
| commit | d5ca0392786de1495bb3219bec19ca3887a678a3 (patch) | |
| tree | 370633f4761200180f510ff0d1e388c985124ce2 | |
| parent | mlt: fix build w/ qt5-5.15.0 (QPainterPath) (diff) | |
common/environment/setup/install.sh: add vcompletion.
Install function for installing shell completions in the appropriate
place according to the shell used.
| -rw-r--r-- | Manual.md | 7 | ||||
| -rw-r--r-- | common/environment/setup/install.sh | 30 |
2 files changed, 36 insertions, 1 deletions
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()* `<file> <shell> [<command>]` + + 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"`. <a id="global_vars"></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: <file> <shell>\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 +} |
