[darcs-devel] [patch1533] bash_completion: better support for multi-level commands

Gian Piero Carrubba gpiero at rm-rf.it
Wed Mar 15 21:18:46 UTC 2017


* [Wed, Mar 15, 2017 at 04:55:53PM +0000] Ben Franksen:
>Thanks, applied (just to screened, for the moment, as I am not good at
>reading much less understanding bash completion...).

Oops, was going to send an amended patch that copied the approach used 
by the zsh completion as it is much cleaner. Attaching a new patch that 
cleanly apply to current screened, instead.

Best,
Gian Piero.
-------------- next part --------------
1 patch for repository valentina:var/repos/darcs/screened:

patch 95ccb661cfe3b8818102a024f9be98642b93b2e6
Author: Gian Piero Carrubba <gpiero at rm-rf.it>
Date:   Wed Mar 15 21:54:04 CET 2017
  * bash_completion: copy the approach used by the zsh completion


New patches:

[bash_completion: copy the approach used by the zsh completion
Gian Piero Carrubba <gpiero at rm-rf.it>**20170315205404
 Ignore-this: 9c530730a1124edd05e86b504ed57ee0
] hunk ./contrib/darcs_completion 14
-    # darcs sh<TAB>
hunk ./contrib/darcs_completion 19
-    # darcs show f<TAB>
-    local -a words=(${COMP_WORDS[1]})
-
-    if (($COMP_CWORD != 2)); then
-        case "${COMP_WORDS[1]}" in
-            # Support 2-level commands:
-            #   convert, optimize, rebase, show
-            # Also support commands with mandatory argument:
-            #   setpref
-            (co*|op*|reb*|set*|sh*)
-                # darcs show files --no-f<TAB>
-                words=("${COMP_WORDS[1]}" "${COMP_WORDS[2]}");;
-            # Support commands with mandatory one or two arguments:
-            #   help
-            (h*)
-                if (($COMP_CWORD == 3)); then
-                    # darcs help show f<TAB>
-                    words=("${COMP_WORDS[1]}" "${COMP_WORDS[2]}")
-                else
-                    case "${COMP_WORDS[2]}" in
-                        # help wants two arguments only when coupled with
-                        # 2-level commands:
-                        #   convert, optimize, rebase, show
-                        (co*|op*|reb*|sh*)
-                            # darcs help show files <TAB>
-                            words=("${COMP_WORDS[1]}" "${COMP_WORDS[2]}" "${COMP_WORDS[3]}")
-                        ;;
-                    esac
-                fi
-                ;;
+    # Store the whole command line substituting the (possibly empty)
+    # to-be-completed word with '--list-options'.
+    local -a words=("${COMP_WORDS[@]}")
+    words[$COMP_CWORD]="--list-options"
+
+    # Options are processed from left to right, so avoid to display the help
+    # page when trying to complete a command line that includes '--help'. It
+    # could be tricked by things like '--repodir --hell', but, come on... you
+    # don't deserve a working completion if you name a directory '--hell'.
+    for w in "${words[@]}"; do
+        case "$w" in
+            (--he*) return 0;;
hunk ./contrib/darcs_completion 32
-    fi
+    done
hunk ./contrib/darcs_completion 37
-    COMPREPLY=( $( darcs "${words[@]}" --list-option | command grep "^${cur//./\\.}") )
+    COMPREPLY=( $( "${words[@]}" 2>/dev/null| command grep "^${cur//./\\.}") )
hunk ./contrib/darcs_completion 65
-

Context:

[bash_completion: better support for multi-level commands
Gian Piero Carrubba <gpiero at rm-rf.it>**20170309110453
 Ignore-this: 5033970fe817bd99e89890115e716dcd
] 
[TAG 2.12.0
Guillaume Hoffmann <guillaumh at gmail.com>**20160429142058
 Ignore-this: 5c8cbe0424942686a2168f9e6fd8e35d
] 
Patch bundle hash:
4d56c20edd2d39ab606793aa053370316df85d51


More information about the darcs-devel mailing list