Hi!

> Reassigning to Debian Xen team, since I that makes more sense. We
> totally missed this on our (release) radar.
> 
> And indeed, we're shipping the upstream completion file now. Adi, I see
> how you're improving it, and I like it.
I'm happy you like it...
 
> So, we should probably ship this instead, but at the same time, the
> right (tm) place to move this is upstream. We're activetly trying to get
> rid of "adjusted copies of upstream stuff" in the packaging.
I think it would be great if you could ship that for Buster because I don't
think upstream will merge it within the next month... ;-)

> Would you mind making an upstream patch out of this? I can help with
> that if needed. Then it gets proper review, and upstream can maintain it
> when commands are added/changed etc.
Find the patch attached; it is based on upstream's repository[1]. Feel free
to submit it upstream (no need to credit me; this is just copied together
from xm and upstream's command list).

best regards,
    Adi

[1] https://xenbits.xen.org/git-http/xen.git
diff --git a/tools/xl/bash-completion b/tools/xl/bash-completion
index b7cd6b3992..9d492c6be5 100644
--- a/tools/xl/bash-completion
+++ b/tools/xl/bash-completion
@@ -1,20 +1,218 @@
+# bash completion for xl                                   -*- shell-script -*-
 # Copy this file to /etc/bash_completion.d/xl.sh
+# this is the original bash completion script for xm modified for use with xl
+
+_xen_domain_names()
+{
+    COMPREPLY=( $( compgen -W "$( xl list 2>/dev/null | \
+        awk '!/Name|Domain-0/ { print $1 }'  )" -- "$cur" ) )
+}
+
+_xen_domain_ids()
+{
+    COMPREPLY=( $( compgen -W "$( xl list 2>/dev/null | \
+        awk '!/Name|Domain-0/ { print $2 }' )" -- "$cur" ) )
+}
 
 _xl()
 {
-	local IFS=$'\n,'
+    local cur prev words cword
+    _init_completion || return
 
-	local cur opts xl
-	COMPREPLY=()
-	cur="${COMP_WORDS[COMP_CWORD]}"
-	xl=xl
+    # TODO: _split_longopt
 
-	if [[ $COMP_CWORD == 1 ]] ; then
-		opts=`${xl} help 2>/dev/null | sed '1,4d' | awk '/^ [^ ]/ {print $1}' | sed 's/$/ ,/g'` && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
-		return 0
-	fi
+    local args command commands options
 
-	return 0
-}
+    # command list is taken from xen-util-common's xl.sh command completion
+    commands=$(xl help 2>/dev/null | sed '1,4d' | awk '/^ [^ ]/ {print $1}' | tr '\n' ' ')
+
+    if [[ $cword -eq 1 ]] ; then
+        COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
+    else
+        if [[ "$cur" == *=* ]]; then
+            prev=${cur/=*/}
+            cur=${cur/*=/}
+        fi
+
+        command=${words[1]}
+        if [[ "$cur" == -* ]]; then
+            # possible options for the command
+            case $command in
+                create)
+                    options='-c'
+                    ;;
+                dmesg)
+                    options='--clear'
+                    ;;
+                list)
+                    options='--long'
+                    ;;
+                reboot)
+                    options='-w -a'
+                    ;;
+                shutdown)
+                    options='-w -a -R -H'
+                    ;;
+                sched-credit)
+                    options='-d -w -c'
+                    ;;
+                block-list|network-list|vtpm-list|vnet-list)
+                    options='-l --long'
+                    ;;
+                getpolicy)
+                    options='--dumpxml'
+                    ;;
+                new)
+                    options='-h --help --help_config -q --quiet --path= -f=
+                        --defconfig= -F= --config= -b --dryrun -x --xmldryrun
+                        -s --skipdtd -p --paused -c --console_autoconnect'
+                    ;;
+            esac
+            COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
+        else
+            case $command in
+                console|destroy|domname|domid|list|mem-set|mem-max| \
+                pause|reboot|rename|shutdown|unpause|vcpu-list|vcpu-pin| \
+                vcpu-set|block-list|network-list|vtpm-list)
+                    _count_args
+                    case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                    esac
+                    ;;
+                migrate)
+                    _count_args
+                        case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                        3)
+                            _known_hosts_real -- "$cur"
+                            ;;
+                    esac
+                    ;;
+                restore|dry-run|vnet-create)
+                    _filedir
+                    ;;
+                save)
+                    _count_args
+                    case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                        3)
+                            _filedir
+                            ;;
+                    esac
+                    ;;
+                sysrq)
+                    _count_args
+                    case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                        3)
+                            COMPREPLY=( $( compgen -W "r s e i u b" \
+                                -- "$cur" ) )
+                            ;;
+                    esac
+                    ;;
+                block-attach)
+                    _count_args
+                    case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                        3)
+                            COMPREPLY=( $( compgen -W "phy: file:" \
+                                -- "$cur" ) )
+                            ;;
+                        5)
+                            COMPREPLY=( $( compgen -W "w r" -- "$cur" ) )
+                            ;;
+                        6)
+                            _xen_domain_names
+                            ;;
+                    esac
+                    ;;
+                block-detach)
+                    _count_args
+                    case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                        3)
+                            COMPREPLY=( $( compgen -W "$( xl block-list $prev \
+                                2>/dev/null | awk '!/Vdev/ { print $1 }' )" \
+                                -- "$cur" ) )
+                            ;;
+                    esac
+                    ;;
+                network-attach)
+                    _count_args
+                    case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                        *)
+                            COMPREPLY=( $( compgen -W "script= ip= mac= bridge=
+                                backend=" -- "$cur" ) )
+                            ;;
+                    esac
+                    ;;
+                network-detach)
+                    _count_args
+                    case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                        3)
+                            COMPREPLY=( $(compgen -W "$( xl network-list $prev \
+                                2>/dev/null | awk '!/Idx/ { print $1 }' )" \
+                                -- "$cur" ) )
+                            ;;
+                    esac
+                    ;;
+                sched-credit)
+                    case $prev in
+                        -d)
+                            _xen_domain_names
+                            return
+                            ;;
+                    esac
+                    ;;
+                create)
+                    # we need to give the full path to the config file and
+                    # do not want to complete any other file outside /etc/xen
+                    _filedir
+                    COMPREPLY+=( \
+                        $( compgen -W '$( command ls /etc/xen/*.cfg 2>/dev/null )' \
+                        -- "$cur" ) )
+                    ;;
+                new)
+                    case $prev in
+                        -f|-F|--defconfig|--config)
+                            _filedir
+                            return
+                            ;;
+                        --path)
+                            _filedir -d
+                            return
+                            ;;
+                    esac
+
+                    _count_args
+                        case $args in
+                        2)
+                            _xen_domain_names
+                            ;;
+                    esac
+                    ;;
+            esac
+        fi
+    fi
+} &&
+complete -F _xl xl
 
-complete -F _xl -o nospace -o default xl
+# ex: filetype=sh

Attachment: signature.asc
Description: PGP signature

Reply via email to