Package: git-phab
Version: 2.9.0~git20170531+6877964-1
Severity: normal
Tags: patch

Dear Maintainer,

The bash-completion script which git-phab installs has a syntax error
(missing } to end the function) and calls a function which is not
defined (_python_argcomplete_global).  The errors were hidden due to
bash-completion redirecting stdout/stderr when loading completion
scripts, which is being changed in an upcoming version.  See
https://github.com/scop/bash-completion/issues/506

I've attached a patch with a functional bash-completion script based on
the output of register-python-argcomplete3.  See patch for specific
details.

Thanks,
Kevin
>From 5d3f5f2a52dcae25509384bc4c1fe708f4b5fb90 Mon Sep 17 00:00:00 2001
Message-Id: 
<5d3f5f2a52dcae25509384bc4c1fe708f4b5fb90.1615499214.git.ke...@kevinlocke.name>
From: Kevin Locke <ke...@kevinlocke.name>
Date: Thu, 11 Mar 2021 13:55:19 -0700
Subject: [PATCH] fix bash-completion script

The previous bash-completion script was non-functional.  Replace it with
a functional bash-completion script generated using:

    register-python-argcomplete3 git-phab | sed '
        s/_python_argcomplete/_git_phab/
        s/"$1"/git-phab/
        s/COMP_LINE="$COMP_LINE"/COMP_LINE="${COMP_LINE\/git phab\/git-phab}"/'

The first replacement renames the completion function to _git_phab,
which is required by the bash-completion script for git to complete `git
phab`.

The second replacement invokes git-phab to perform the completion,
rather than the first function argument, since the git bash-completion
script does not pass any arguments to the completion function.

The third replaces 'git phab' with 'git-phab' in $COMP_LINE so that
argcomplete can recognize the script name when parsing $COMP_LINE.

Note: It would be possible to Build-Depend on python3-argcomplete and
generate this script during build.  (See diffoscope for an example.)
However, making the above changes would be fragile, since the output of
register-python-argcomplete3 may change arbitrarily, so this patch uses
the edited script.

Signed-off-by: Kevin Locke <ke...@kevinlocke.name>
---
 debian/bash_completion.d/git-phab | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/debian/bash_completion.d/git-phab 
b/debian/bash_completion.d/git-phab
index 6603f72..e9a3ea5 100644
--- a/debian/bash_completion.d/git-phab
+++ b/debian/bash_completion.d/git-phab
@@ -1,7 +1,22 @@
-function _git_phab()
-{
-  COMP_WORDS=(git-phab ${COMP_WORDS[@]:2})
-  COMP_CWORD=$((COMP_CWORD - 1))
-  COMP_LINE=${COMP_LINE/git phab/git-phab}
-  _python_argcomplete_global git-phab
 
+_git_phab() {
+    local IFS=$'\013'
+    local SUPPRESS_SPACE=0
+    if compopt +o nospace 2> /dev/null; then
+        SUPPRESS_SPACE=1
+    fi
+    COMPREPLY=( $(IFS="$IFS" \
+                  COMP_LINE="${COMP_LINE/git phab/git-phab}" \
+                  COMP_POINT="$COMP_POINT" \
+                  COMP_TYPE="$COMP_TYPE" \
+                  _ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" \
+                  _ARGCOMPLETE=1 \
+                  _ARGCOMPLETE_SUPPRESS_SPACE=$SUPPRESS_SPACE \
+                  git-phab 8>&1 9>&2 1>/dev/null 2>/dev/null) )
+    if [[ $? != 0 ]]; then
+        unset COMPREPLY
+    elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "$COMPREPLY" =~ [=/:]$ ]]; then
+        compopt -o nospace
+    fi
+}
+complete -o nospace -o default -F _git_phab "git-phab"
-- 
2.30.1

Reply via email to