core/cli: add completion for hpi command

This commit is contained in:
Sean Breckenridge 2022-02-15 18:20:47 -08:00 committed by karlicoss
parent f1b18beef7
commit 8b01674fed
5 changed files with 133 additions and 0 deletions

29
misc/completion/bash/_hpi Normal file
View file

@ -0,0 +1,29 @@
_hpi_completion() {
local IFS=$'\n'
local response
response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD _HPI_COMPLETE=bash_complete $1)
for completion in $response; do
IFS=',' read type value <<< "$completion"
if [[ $type == 'dir' ]]; then
COMREPLY=()
compopt -o dirnames
elif [[ $type == 'file' ]]; then
COMREPLY=()
compopt -o default
elif [[ $type == 'plain' ]]; then
COMPREPLY+=($value)
fi
done
return 0
}
_hpi_completion_setup() {
complete -o nosort -F _hpi_completion hpi
}
_hpi_completion_setup;