Skip to content

Commit f3a8518

Browse files
committed
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
1 parent 0f4f7ab commit f3a8518

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

bash-completion.el

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,7 @@ returned."
395395
" [[ \"$l\" = \"==eof==\" ]] && break;"
396396
" if [[ -d \"${l/#\~/$HOME}\" ]]; then echo \"$l/\"; else echo \"$l\"; fi; "
397397
" done; "
398-
"} ; case \"${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}\" in "
399-
" 4.[23]) function __ebcompgen {"
400-
;; wait cannot be used with <(...) before Bash 4.4.
398+
"} ; function __ebcompgen {"
401399
" local fd p=$(mktemp -u);"
402400
" mkfifo \"$p\";"
403401
" exec {fd}<>\"$p\";"
@@ -407,15 +405,7 @@ returned."
407405
" compgen \"$@\" >&$fd 2>/dev/null; echo ==eof==>&$fd;"
408406
" wait $pid 2>/dev/null;"
409407
" exec {fd}>&-;"
410-
" } ;;"
411-
" *) function __ebcompgen {"
412-
;; __ebcfixdirs post-processes the output to add / after
413-
;; directories. This is done in this way instead of using a pipe
414-
;; to avoid executing compgen in a subshell, as completion
415-
;; functions sometimes define new functions.
416-
" compgen \"$@\" 2>/dev/null > >(__ebcfixdirs); wait $!; "
417-
" } ;;"
418-
"esac; "
408+
" }; "
419409
"function __ebcwrapper {"
420410
" COMP_TYPE=9; COMP_KEY=9; _EMACS_COMPOPT=\"\";"
421411
" eval $__EBCWRAPPER;"

test/bash-completion-integration-test.el

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,4 +853,19 @@ $ ")))))
853853
(should (equal nil (funcall compfunc-nonprefix "babeetai"
854854
(lambda (c) (equal "babeedai" c)) 'lambda))))))
855855

856+
857+
(ert-deftest bash-completion_test-issue-74 ()
858+
(bash-completion_test-with-shell-harness
859+
(concat ; .bashrc
860+
"_mycmd() {\n"
861+
" readarray -t opts < <(printf \"foo\nbar\")\n"
862+
" COMPREPLY=($(compgen -W \"${opts[*]}\" -- \"${COMP_WORDS[$COMP_CWORD]}\"))\n"
863+
"}\n"
864+
"complete -F _mycmd mycmd\n")
865+
nil ;; use-separate-process
866+
867+
(should (equal "mycmd bar "
868+
(bash-completion_test-complete "mycmd b")))))
869+
870+
856871
;;; bash-completion-integration-test.el ends here

0 commit comments

Comments
 (0)