From bf19655286d2d49479da18bf3d2c5c537e029f7f Mon Sep 17 00:00:00 2001 From: pvincent Date: Mon, 6 Apr 2026 15:02:47 +0400 Subject: [PATCH] compopt -o nospace --- lib/miaou.completion | 51 +++++++------------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/lib/miaou.completion b/lib/miaou.completion index 9246ca3..2104f86 100644 --- a/lib/miaou.completion +++ b/lib/miaou.completion @@ -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"