|
|
|
@ -30,7 +30,7 @@ function _miaou_login { |
|
|
|
esac |
|
|
|
} |
|
|
|
|
|
|
|
function _miaou_exec2() { |
|
|
|
function _miaou_exec() { |
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}" |
|
|
|
local prev="${COMP_WORDS[COMP_CWORD - 1]}" |
|
|
|
local container="${COMP_WORDS[1]}" |
|
|
|
@ -71,10 +71,8 @@ EOF |
|
|
|
command=${COMP_WORDS[dashdash_pos + 1]} |
|
|
|
completion_command=$( |
|
|
|
incus exec "$container" -- bash << EOF |
|
|
|
source /etc/bash_completion |
|
|
|
for i in /etc/bash_completion.d/*; do source \$i; done |
|
|
|
[[ -f /usr/share/bash-completion/completions/$command ]] && source /usr/share/bash-completion/completions/$command |
|
|
|
complete -p "$command" | grep -oP '(?<=-F )\S+' |
|
|
|
complete -p "$command" 2>/dev/null | grep -oP '(?<=-F )\S+' |
|
|
|
EOF |
|
|
|
) |
|
|
|
if [[ -n $completion_command ]]; then |
|
|
|
@ -86,6 +84,8 @@ EOF |
|
|
|
COMP_POINT=$((COMP_POINT + 1)) |
|
|
|
|
|
|
|
# echo -e "\ncompletion_command $completion_command \nprev=$prev \ncur=$cur \nCOMP_WORDS=(${COMP_WORDS[@]}) \nCOMP_CWORD=$COMP_CWORD \nCOMP_LINE=$COMP_LINE \nCOMP_POINT=$COMP_POINT" >&2 |
|
|
|
echo -e "\ncommand={$completion_command}" >&2 |
|
|
|
|
|
|
|
COMPREPLY=($( |
|
|
|
incus exec "$container" -- bash << EOF |
|
|
|
source /etc/bash_completion |
|
|
|
@ -104,10 +104,12 @@ EOF |
|
|
|
EOF |
|
|
|
)) |
|
|
|
else |
|
|
|
compopt -o filenames |
|
|
|
compopt -o nospace |
|
|
|
COMPREPLY=($( |
|
|
|
incus exec "$container" -- bash << EOF |
|
|
|
source /etc/bash_completion |
|
|
|
compgen -f -- "$cur" |
|
|
|
compgen -f "$cur" # | sed 's/\([^ ]*\)/\1\//g' |
|
|
|
EOF |
|
|
|
)) |
|
|
|
fi |
|
|
|
@ -115,42 +117,5 @@ EOF |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function _miaou_exec { |
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}" |
|
|
|
local prev="${COMP_WORDS[COMP_CWORD - 1]}" |
|
|
|
local container="${COMP_WORDS[1]}" |
|
|
|
|
|
|
|
case $COMP_CWORD in |
|
|
|
1) |
|
|
|
# first argument — containers |
|
|
|
COMPREPLY=($(compgen -W "$(_incus_container)" -- "$cur")) |
|
|
|
;; |
|
|
|
2) |
|
|
|
# second argument - options |
|
|
|
COMPREPLY=($(compgen -W "--" -- "$cur")) |
|
|
|
;; |
|
|
|
*) |
|
|
|
# echo "coucou" >&2 |
|
|
|
# COMPREPLY=($(compgen -W \ |
|
|
|
# "$(incus exec "$container" -- bash -c 'compgen -c' 2> /dev/null)" \ |
|
|
|
# -- "$cur")) |
|
|
|
|
|
|
|
COMPREPLY=($(compgen -W \ |
|
|
|
"$(incus exec "$container" -- \ |
|
|
|
bash -c "compgen -c -- $(printf '%q' "$cur")" 2> /dev/null)" \ |
|
|
|
-- "$cur")) |
|
|
|
;; |
|
|
|
|
|
|
|
esac |
|
|
|
} |
|
|
|
|
|
|
|
complete -F _miaou_login "miaou-login" |
|
|
|
complete -F _miaou_exec2 "miaou-exec" |
|
|
|
|
|
|
|
function _toto { |
|
|
|
for i in ${!COMP_WORDS[@]}; do echo "COMP_WORDS[$i]=${COMP_WORDS[$i]}"; done |
|
|
|
echo COMP_CWORD=$COMP_CWORD |
|
|
|
COMPREPLY=(one two three) |
|
|
|
} |
|
|
|
|
|
|
|
complete -F _toto toto |
|
|
|
complete -F _miaou_exec "miaou-exec" |