[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion de2c84451c 1/4: Wrap calls to compgen into
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion de2c84451c 1/4: Wrap calls to compgen into a function. |
Date: |
Thu, 2 Mar 2023 14:59:52 -0500 (EST) |
branch: elpa/bash-completion
commit de2c84451c66a7760a02a08bc5eeaa5f000fdd7f
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <stephane@fuzzy.zia>
Wrap calls to compgen into a function.
This patch adds a function __ebcompgen that calls compgen and
applies __ebfixdirs. This prepares the way for executing this
part differently on version of Bash older than 4.4, which doesn't
support getting the PID of subshells executed with <(...).
See issue #64
---
bash-completion.el | 21 +++++++++++----------
test/bash-completion-test.el | 18 +++++++++---------
2 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 35a4dc6e3c..db64f9066c 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -380,6 +380,12 @@ returned."
" while read l; do "
" if [[ -d \"${l/#\~/$HOME}\" ]]; then echo \"$l/\"; else echo
\"$l\"; fi; "
" done; "
+ "} ; 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 $!; "
"} ; function __ebcwrapper {"
" COMP_TYPE=9; COMP_KEY=9; _EMACS_COMPOPT=\"\";"
" eval $__EBCWRAPPER;"
@@ -1301,10 +1307,10 @@ completion candidates."
(bash-completion-cd-command-prefix))
(cond
((eq 'command completion-type)
- (concat "compgen -b -c -a -A function -- " quoted-stub))
+ (concat "__ebcompgen -b -c -a -A function -- " quoted-stub))
((eq 'default completion-type)
- (concat "compgen -o default -- " quoted-stub))
+ (concat "__ebcompgen -o default -- " quoted-stub))
((and (eq 'custom completion-type) (or (member "-F" compgen-args)
(member "-C" compgen-args)))
@@ -1314,7 +1320,7 @@ completion candidates."
(function-name (car (cdr function))))
(setcar function "-F")
(setcar (cdr function) "__ebcwrapper")
- (format "__EBCWRAPPER=%s compgen %s -- %s"
+ (format "__EBCWRAPPER=%s __ebcompgen %s -- %s"
(bash-completion-quote
(format "COMP_LINE=%s; COMP_POINT=$(( 1 + ${#COMP_LINE} ));
COMP_CWORD=%s; COMP_WORDS=( %s ); %s %s %s %s"
(bash-completion-quote (bash-completion--line comp))
@@ -1330,15 +1336,10 @@ completion candidates."
quoted-stub)))
((eq 'custom completion-type)
;; simple custom completion
- (format "compgen %s -- %s"
+ (format "__ebcompgen %s -- %s"
(bash-completion-join compgen-args)
quoted-stub))
- (t (error "Unsupported completion type: %s" completion-type)))
- ;; __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.
- " 2>/dev/null > >(__ebcfixdirs); wait $!")))
+ (t (error "Unsupported completion type: %s" completion-type))))))
;;;###autoload
(defun bash-completion-refresh ()
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index dc9a1f0a71..e121a0c4c1 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -374,7 +374,7 @@ home.lan' scp"
(bash-completion-use-separate-processes t))
(should
(equal (concat "cd &>/dev/null /test"
- " && compgen -o default -- worl 2>/dev/null >
>(__ebcfixdirs); wait $!")
+ " && __ebcompgen -o default -- worl")
(bash-completion-generate-line
(bash-completion--make
:line "hello worl"
@@ -385,7 +385,7 @@ home.lan' scp"
;; custom completion no function or command
(should (equal
- "cd &>/dev/null /test && compgen -A -G '*.txt' -- worl
2>/dev/null > >(__ebcfixdirs); wait $!"
+ "cd &>/dev/null /test && __ebcompgen -A -G '*.txt' -- worl"
(bash-completion-generate-line
(bash-completion--make
:line "zorg worl"
@@ -403,7 +403,7 @@ home.lan' scp"
"COMP_POINT=$(( 1 + ${#COMP_LINE} )); COMP_CWORD=2; "
"COMP_WORDS=( zorg blah worl ); "
"__zorg zorg worl blah' "
- "compgen -F __ebcwrapper -- worl 2>/dev/null > >(__ebcfixdirs);
wait $!")
+ "__ebcompgen -F __ebcwrapper -- worl")
(bash-completion-generate-line
(bash-completion--make
:line "zorg blah worl"
@@ -422,7 +422,7 @@ home.lan' scp"
"COMP_CWORD=1; "
"COMP_WORDS=( zorg worl ); "
"__zorg zorg worl zorg' "
- "compgen -F __ebcwrapper -- worl 2>/dev/null > >(__ebcfixdirs);
wait $!")
+ "__ebcompgen -F __ebcwrapper -- worl")
(bash-completion-generate-line
(bash-completion--make
:line "zorg worl"
@@ -434,7 +434,7 @@ home.lan' scp"
;; command completion
(should (equal
- "cd &>/dev/null /test && compgen -b -c -a -A function -- worl
2>/dev/null > >(__ebcfixdirs); wait $!"
+ "cd &>/dev/null /test && __ebcompgen -b -c -a -A function -- worl"
(bash-completion-generate-line
(bash-completion--make
:line "worl"
@@ -895,7 +895,7 @@ before calling `bash-completion-dynamic-complete-nocomint'.
(should (equal
(list 7 9 '("hell" "hello1" "hello2"))
(bash-completion-dynamic-complete-nocomint 3 (point))))
- (should (equal "cd &>/dev/null /tmp/test && compgen -o default -- he
2>/dev/null > >(__ebcfixdirs); wait $!"
+ (should (equal "cd &>/dev/null /tmp/test && __ebcompgen -o default -- he"
(pop --captured-commands)))))
(ert-deftest bash-completion-simple-dynamic-table-test ()
@@ -1023,7 +1023,7 @@ before calling
`bash-completion-dynamic-complete-nocomint'.
(should (equal
(concat
"cd &>/dev/null /tmp/test && "
- "compgen -o default -- 'Documents/Modes d'\\''emplois/'
2>/dev/null > >(__ebcfixdirs); wait $!")
+ "__ebcompgen -o default -- 'Documents/Modes d'\\''emplois/'")
(pop --captured-commands)))))
(ert-deftest bash-completion-complete-single-quoted-dir ()
@@ -1057,7 +1057,7 @@ before calling
`bash-completion-dynamic-complete-nocomint'.
'("bin/" "bind")
(nth 2 (bash-completion-dynamic-complete-nocomint 3 (point)))))
(should (equal (concat "cd &>/dev/null /tmp/test && "
- "compgen -b -c -a -A function -- b 2>/dev/null >
>(__ebcfixdirs); wait $!")
+ "__ebcompgen -b -c -a -A function -- b")
(pop --captured-commands)))))
(ert-deftest bash-completion-complete-command-with-space ()
@@ -1068,7 +1068,7 @@ before calling
`bash-completion-dynamic-complete-nocomint'.
'("some\\ command ")
(nth 2 (bash-completion-dynamic-complete-nocomint 3 (point)))))
(should (equal (concat "cd &>/dev/null /tmp/test && "
- "compgen -b -c -a -A function -- 'some c'
2>/dev/null > >(__ebcfixdirs); wait $!")
+ "__ebcompgen -b -c -a -A function -- 'some c'")
(pop --captured-commands)))))
(ert-deftest bash-completion-failed-completion ()