[virt-tools-list] [virt-manager] [RFC PATCH 8/9] Bash completion file
Cole Robinson
crobinso at redhat.com
Sun Nov 18 02:21:20 UTC 2018
On 11/14/2018 03:12 AM, Lin Ma wrote:
> The most of content of this file comes from the output of the command '
> register-python-argcomplete $MY-SCRIPT', plus some changes.
> For the details about argcomplete, Please refer to
> https://pypi.org/project/argcomplete/ or
> https://github.com/kislyuk/argcomplete
>
> With this patchset, Users can use completion in bash.
> ex:
>
> $ virt-xml --<TAB><TAB>
> $ virt-install --disk <TAB><TAB>
> $ virt-install --panic model=isa,<TAB><TAB>
> $ virt-install --controller model=virtio-scsi,ty<TAB><TAB>
>
> Signed-off-by: Lin Ma <lma at suse.com>
> ---
> bash-completion/virtmanager | 40 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 40 insertions(+)
> create mode 100644 bash-completion/virtmanager
>
Please move this to data/bash-completion, not a top level dir in the git
tree
> diff --git a/bash-completion/virtmanager b/bash-completion/virtmanager
> new file mode 100644
> index 00000000..c0ad0b84
> --- /dev/null
> +++ b/bash-completion/virtmanager
> @@ -0,0 +1,40 @@
> +#!/bin/bash
> +
> +# Run something, muting output or redirecting it to the debug stream
> +# depending on the value of _ARC_DEBUG.
> +__python_argcomplete_run() {
> + if [[ -z "$_ARC_DEBUG" ]]; then
> + "$@" 8>&1 9>&2 1>/dev/null 2>&1
> + else
> + "$@" 8>&1 9>&2 1>&9 2>&1
> + fi
> +}
> +
> +_python_argcomplete() {
> + if [[ "$COMP_WORDBREAKS" != *,* ]]; then
> + COMP_WORDBREAKS="${COMP_WORDBREAKS},"
> + fi
> + local IFS=$'\013'
> + local SUPPRESS_SPACE=0
> + if compopt +o nospace 2> /dev/null; then
> + SUPPRESS_SPACE=1
> + fi
> + COMP_WORDS[4]=""
> + COMPREPLY=( $(IFS="$IFS" \
> + COMP_LINE="$COMP_LINE" \
> + COMP_POINT="$COMP_POINT" \
> + COMP_TYPE="$COMP_TYPE" \
> + _ARGCOMPLETE_COMP_WORDBREAKS="\"'><;|&(:" \
> + _ARGCOMPLETE=1 \
> + _ARGCOMPLETE_SUPPRESS_SPACE=$SUPPRESS_SPACE \
> + __python_argcomplete_run "$1") )
> + if [[ $? != 0 ]]; then
> + unset COMPREPLY
> + elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "$COMPREPLY" =~ [=/:]$ ]]; then
> + compopt -o nospace
> + fi
> +}
> +complete -o nospace -o default -F _python_argcomplete virt-install &&
> +complete -o nospace -o default -F _python_argcomplete virt-clone &&
> +complete -o nospace -o default -F _python_argcomplete virt-xml &&
> +complete -o nospace -o default -F _python_argcomplete virt-convert
>
Okay I haven't looked to deeply into this format here, kinda looks like
black magic :)
But does this launch each tool for each completion attempt? Might
explain why the completion is pretty slow in my testing. I don't want to
maintain 4 files but maybe we could use sed to splice in the tool name
at setup.py build time. Would also allow simplifying the setup.py
process a bit. I'd be happy to fix these bits after the initial series
though
Thanks,
Cole
More information about the virt-tools-list
mailing list