branch: elpa/bash-completion commit f3a85184ef9cc925bedcdbd62f66dd63a658f181 Author: Stephane Zermatten <szerm...@gmx.net> Commit: Stephane Zermatten <szerm...@gmx.net>
Fix strange issue with scripts using < <(cmd). Before this change, bash-completion.el would check the version of Bash and if the version was recent enough, use compgen ... > >(__ecbfixdirs); wait $! to post-process the output of compgen. This seems to be causing strange behaviors in scripts using ... < <(cmd) This change always falls back to the unoptimized __ecbfixdirs, which uses pipes and doesn't seem to trigger this issue. There's most likely a better solution, but until then, this seems to work. Issue #74 --- bash-completion.el | 14 ++------------ test/bash-completion-integration-test.el | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bash-completion.el b/bash-completion.el index 070f94a1a3..6092d2e946 100644 --- a/bash-completion.el +++ b/bash-completion.el @@ -395,9 +395,7 @@ returned." " [[ \"$l\" = \"==eof==\" ]] && break;" " if [[ -d \"${l/#\~/$HOME}\" ]]; then echo \"$l/\"; else echo \"$l\"; fi; " " done; " - "} ; case \"${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}\" in " - " 4.[23]) function __ebcompgen {" - ;; wait cannot be used with <(...) before Bash 4.4. + "} ; function __ebcompgen {" " local fd p=$(mktemp -u);" " mkfifo \"$p\";" " exec {fd}<>\"$p\";" @@ -407,15 +405,7 @@ returned." " compgen \"$@\" >&$fd 2>/dev/null; echo ==eof==>&$fd;" " wait $pid 2>/dev/null;" " exec {fd}>&-;" - " } ;;" - " *) function __ebcompgen {" - ;; __ebcfixdirs post-processes the output to add / after - ;; directories. This is done in this way instead of using a pipe - ;; to avoid executing compgen in a subshell, as completion - ;; functions sometimes define new functions. - " compgen \"$@\" 2>/dev/null > >(__ebcfixdirs); wait $!; " - " } ;;" - "esac; " + " }; " "function __ebcwrapper {" " COMP_TYPE=9; COMP_KEY=9; _EMACS_COMPOPT=\"\";" " eval $__EBCWRAPPER;" diff --git a/test/bash-completion-integration-test.el b/test/bash-completion-integration-test.el index c233f4dcb8..b85f57fd58 100644 --- a/test/bash-completion-integration-test.el +++ b/test/bash-completion-integration-test.el @@ -853,4 +853,19 @@ $ "))))) (should (equal nil (funcall compfunc-nonprefix "babeetai" (lambda (c) (equal "babeedai" c)) 'lambda)))))) + +(ert-deftest bash-completion_test-issue-74 () + (bash-completion_test-with-shell-harness + (concat ; .bashrc + "_mycmd() {\n" + " readarray -t opts < <(printf \"foo\nbar\")\n" + " COMPREPLY=($(compgen -W \"${opts[*]}\" -- \"${COMP_WORDS[$COMP_CWORD]}\"))\n" + "}\n" + "complete -F _mycmd mycmd\n") + nil ;; use-separate-process + + (should (equal "mycmd bar " + (bash-completion_test-complete "mycmd b"))))) + + ;;; bash-completion-integration-test.el ends here