[virt-tools-list] [virt-manager] [RFC PATCH 0/9] Tab completion in bash shell via the argcomplete

Lin Ma lma at suse.com
Fri Dec 7 06:17:43 UTC 2018


On 11/18/18 9:43 AM, Cole Robinson wrote:
> On 11/14/2018 03:12 AM, Lin Ma wrote:
>> Hi all,
>>
>> These draft patches add the tab completion in bash for virt-* utilities.
>>
>> We've been using the argparse to help parse handling, So I think that 
>> the
>> argcomplete is a good option to deal with argument/sub-options 
>> completion
>> in bash shell for virt-manager project. Argcomplete returns the 
>> completion
>> result via fd 8.
>> After applying these patches, The python3 argcomplete is required while
>> running virt-* utilities.
>>
>> For the details about argcomplete, Please refer to:
>> https://github.com/kislyuk/argcomplete  or
>> https://pypi.org/project/argcomplete/
>>
>
> Wow, nice work! I didn't expect this to be so minimally invasive. I 
> haven't heard of argcomplete, it's a handy project for sure.
>
>> ex:
>> $ virt-clone --<TAB><TAB>
>> ...
>> --auto-clone     --debug    --help     --nonsparse    --reflink
>> --check          --file     --mac      --nvram        --replace
>> ...
>>
>> $ virt-install --p<TAB><TAB>
>> --panic      --parallel   --paravirt   --pm         --print-xml --pxe
>>
>> $ virt-install --panic <TAB><TAB>
>> clearxml=  iobase=    model=
>>
>> $ virt-install --panic model=isa,<TAB><TAB>
>> clearxml=  iobase=
>>
>> $ virt-install --disk <TAB><TAB>
>> ...
>> bus=    cache=      format=     path=   serial=     size=
>> ...
>>
>> $ virt-install --disk 
>> path=/storage/vms/sles15/disk0.raw,format=raw,<TAB><TAB>cache=none
>> ...
>> bus=    format=     serial=     path=   size=
>> ...
>>
>>
>> $ virt-install --network model=rtl8139,ty<TAB><TAB>
>> $ virt-install --network model=rtl8139,type=
>>
>>
>> * A side effect of patches is:
>> Due to the sub options of arguments of virt-* is comma separated, It 
>> needs
>> to add comma into $COMP_WORDBREAKS to support sub options completion.
>> That means, Once we used TAB for option completion, The change 
>> impacts the
>> current shell.
>>
>
> I barely looked at this so I don't fully understand the issue, but we 
> definitely can't change shell behavior after some tab completion 
> attempts. Maybe this helps finding a better solution?
>
> https://stackoverflow.com/questions/10528695/how-to-reset-comp-wordbreaks-without-affecting-other-completion-script 
>
Sorry for the late responding.

I'm afraid that it doesn't help due to what we need is add a word break 
into COMP_WORDBREAKS, not remove or ignore one.
I used to try to search some solutions for this case, But it seems no 
perfect way.

The current design is similar with bash completion of perf, The perf 
completion modifies COMP_WORDBREAKS as well and affect current shell only.

Thanks,
Lin




More information about the virt-tools-list mailing list