Add bash-completion

This assumes that we will be installing to a Void Linux system with 'bash-completion' package installed.
Notes:
- sourcing the xbps bash completion for forward proofing.
- calling out to `_xbps_all_packages` and `_xbps_installed_packages` directly, as `_xbps_complete` expects $1 to be one of the xbps-* commnads.
- none of the extra `-args` are implemented due to the hardcoded $1 problem mentioned above.
This commit is contained in:
Krsna Mahapatra 2020-04-08 21:02:24 -10:00 committed by GitHub
parent 3c729dd338
commit fa321af522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
source /usr/share/bash-completion/completions/xbps
_vpm()
{
local cur prev words cword
_init_completion || return
local subcommands='sync
update
listrepos
repolist
addrepo
info
filelist
deps
reverse
search
searchfile
list
install
devinstall
listalternatives
setalternative
reconfigure
forceinstall
remove
removerecursive
cleanup
autoremove
help
helppager'
local all_pkgs='info|filelist|deps|reverse|search|install|devinstall'
local installed_pkgs='listalternatives|setalternative|reconfigure|forceinstall|remove|removerecursive'
if [[ $prev == @($1) ]]; then
COMPREPLY=( $( compgen -W "$subcommands" -- "$cur") )
elif [[ $prev == @($all_pkgs) ]]; then
COMPREPLY=( $(compgen -W '$(_xbps_all_packages)' -- "$cur") )
elif [[ $prev == @($installed_pkgs) ]]; then
COMPREPLY=( $(compgen -W '$(_xbps_installed_packages)' -- "$cur") )
fi
} &&
complete -F _vpm vpm