From 92b314677fd86cf6db5629bef19ccb08a04e27b6 Mon Sep 17 00:00:00 2001 From: pvincent Date: Tue, 7 Apr 2026 17:55:33 +0400 Subject: [PATCH] dirty fix for _comp_complete_longopt --- lib/miaou.completion | 17 +++++++++++------ tools/miaou-create | 25 ++++++++++++++----------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/miaou.completion b/lib/miaou.completion index 4a193dc..0c4b9e3 100644 --- a/lib/miaou.completion +++ b/lib/miaou.completion @@ -61,25 +61,26 @@ function _miaou_exec() { if ((COMP_CWORD == 3)); then # command or file from inside container - compopt -o filenames - compopt -o nospace COMPREPLY=($( incus exec "$container" -- bash << EOF source /etc/bash_completion compgen -c -- "$cur" - compgen -f -- "$cur" EOF )) + return fi if ((COMP_CWORD > 3)); then command=${COMP_WORDS[dashdash_pos + 1]} + # echo -e "\nCOMMAND:$command from CONTAINER\n" >&2 + completion_command=$( incus exec "$container" -- bash << EOF - [[ -f /usr/share/bash-completion/completions/$command ]] && source /usr/share/bash-completion/completions/$command - complete -p "$command" 2>/dev/null | grep -oP '(?<=-F )\S+' + source /etc/bash_completion + [[ -f /usr/share/bash-completion/completions/$command ]] && source /usr/share/bash-completion/completions/$command + complete -p "$command" 2>/dev/null | grep -oP '(?<=-F )\S+' EOF ) if [[ -n $completion_command ]]; then @@ -91,7 +92,6 @@ 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 - COMPREPLY=($( incus exec "$container" -- bash << EOF source /etc/bash_completion @@ -109,6 +109,11 @@ EOF echo \${COMPREPLY[@]} EOF )) + if [[ $completion_command == '_comp_complete_longopt' ]]; then + compopt -o filenames + compopt -o nospace + fi + else compopt -o filenames compopt -o nospace diff --git a/tools/miaou-create b/tools/miaou-create index 5199e69..7342f6e 100755 --- a/tools/miaou-create +++ b/tools/miaou-create @@ -59,13 +59,6 @@ function parse_options { [[ -n $CONTAINER ]] || (usage && exit 1) } -function create { - incus --project "$PROJECT_SANDBOX" copy --instance-only --refresh "$TEMPLATE_SANDBOX" "$CONTAINER" --target-project $(incus project get-current) - incus file delete "$CONTAINER/etc/machine-id" - incus start "$CONTAINER" - customize_host "$CONTAINER" -} - function mount_miaou_bash { printenv MIAOU_BASH_DIR > /dev/null || (echo >&2 "Warn: environment variable MIAOU_BASH_DIR is missing!" && return) @@ -80,13 +73,13 @@ function mount_miaou_bash { function build_sandbox_project { if ! incus project show $PROJECT_SANDBOX > /dev/null; then incus project create $PROJECT_SANDBOX - incus profile device add default root disk path=/ pool=default --project $PROJECT_SANDBOX - incus profile device add default eth0 nic name=eth0 network=incusbr0 --project $PROJECT_SANDBOX + incus --project $PROJECT_SANDBOX profile device add default root disk path=/ pool=default + incus --project $PROJECT_SANDBOX profile device add default eth0 nic name=eth0 network=incusbr0 fi } function refresh_template { - if ! incus --project "$PROJECT_SANDBOX" info "$TEMPLATE_SANDBOX" | grep '^Status: RUNNING'; then + if incus --project "$PROJECT_SANDBOX" info "$TEMPLATE_SANDBOX" | grep '^Status: STOPPED'; then incus --project "$PROJECT_SANDBOX" start "$TEMPLATE_SANDBOX" fi incus --project "$PROJECT_SANDBOX" exec "$TEMPLATE_SANDBOX" -- bash << EOF @@ -150,11 +143,21 @@ function assert_not_sandboxing { || true } +function create { + if incus --project "$PROJECT_SANDBOX" info "$TEMPLATE_SANDBOX" | grep '^Status: RUNNING'; then + incus --project "$PROJECT_SANDBOX" stop "$TEMPLATE_SANDBOX" + fi + incus --project "$PROJECT_SANDBOX" copy --instance-only --refresh "$TEMPLATE_SANDBOX" "$CONTAINER" --target-project $(incus project get-current) + incus file delete "$CONTAINER/etc/machine-id" + incus config unset "$CONTAINER" volatile.eth0.hwaddr + incus start "$CONTAINER" + customize_host "$CONTAINER" +} + # MAIN set -Eue parse_options "$@" - assert_not_sandboxing prepare_template_for_quick_creation create