common/environment/setup/install.sh: add vcompletion.
Install function for installing shell completions in the appropriate place according to the shell used.
This commit is contained in:
parent
a9b37be644
commit
d5ca039278
@ -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>
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user