You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/09/07 12:59:14 UTC

[maven-mvnd] branch master updated: Add missing function for mvnd-bash-completion, fixes #670 (#682)

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git


The following commit(s) were added to refs/heads/master by this push:
     new 10a5240  Add missing function for mvnd-bash-completion, fixes #670 (#682)
10a5240 is described below

commit 10a5240802358c48d27d2a1f4bda19ea1e88082d
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Sep 7 14:59:09 2022 +0200

    Add missing function for mvnd-bash-completion, fixes #670 (#682)
---
 dist/src/main/distro/bin/mvnd-bash-completion.bash | 71 ++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/dist/src/main/distro/bin/mvnd-bash-completion.bash b/dist/src/main/distro/bin/mvnd-bash-completion.bash
index 65bed44..4b90fea 100644
--- a/dist/src/main/distro/bin/mvnd-bash-completion.bash
+++ b/dist/src/main/distro/bin/mvnd-bash-completion.bash
@@ -23,6 +23,77 @@ function_exists()
     return $?
 }
 
+# This function can be used to access a tokenized list of words
+# on the command line:
+#
+#   __git_reassemble_comp_words_by_ref '=:'
+#   if test "${words_[cword_-1]}" = -w
+#   then
+#       ...
+#   fi
+#
+# The argument should be a collection of characters from the list of
+# word completion separators (COMP_WORDBREAKS) to treat as ordinary
+# characters.
+#
+# This is roughly equivalent to going back in time and setting
+# COMP_WORDBREAKS to exclude those characters.  The intent is to
+# make option types like --date=<type> and <rev>:<path> easy to
+# recognize by treating each shell word as a single token.
+#
+# It is best not to set COMP_WORDBREAKS directly because the value is
+# shared with other completion scripts.  By the time the completion
+# function gets called, COMP_WORDS has already been populated so local
+# changes to COMP_WORDBREAKS have no effect.
+#
+# Output: words_, cword_, cur_.
+function_exists __git_reassemble_comp_words_by_ref ||
+__git_reassemble_comp_words_by_ref()
+{
+    local exclude i j first
+    # Which word separators to exclude?
+    exclude="${1//[^$COMP_WORDBREAKS]}"
+    cword_=$COMP_CWORD
+    if [ -z "$exclude" ]; then
+        words_=("${COMP_WORDS[@]}")
+        return
+    fi
+    # List of word completion separators has shrunk;
+    # re-assemble words to complete.
+    for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
+        # Append each nonempty word consisting of just
+        # word separator characters to the current word.
+        first=t
+        while
+            [ $i -gt 0 ] &&
+            [ -n "${COMP_WORDS[$i]}" ] &&
+            # word consists of excluded word separators
+            [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
+        do
+            # Attach to the previous token,
+            # unless the previous token is the command name.
+            if [ $j -ge 2 ] && [ -n "$first" ]; then
+                ((j--))
+            fi
+            first=
+                words_[$j]=${words_[j]}${COMP_WORDS[i]}
+            if [ $i = $COMP_CWORD ]; then
+                cword_=$j
+            fi
+            if (($i < ${#COMP_WORDS[@]} - 1)); then
+                ((i++))
+            else
+                # Done.
+                return
+            fi
+        done
+        words_[$j]=${words_[j]}${COMP_WORDS[i]}
+        if [ $i = $COMP_CWORD ]; then
+            cword_=$j
+        fi
+    done
+}
+
 function_exists _get_comp_words_by_ref ||
 _get_comp_words_by_ref ()
 {