8000 use interactive shells and bind to work around issue in bash (#506) · kislyuk/argcomplete@27e57fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 27e57fb

Browse files
use interactive shells and bind to work around issue in bash (#506)
* use interactive shells and bind to work around issue in bash * fix bash version * Ignore warning about non-interactive mode, instead of using an interactive subshell.
1 parent 5c949e9 commit 27e57fb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

argcomplete/completers.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ def __call__(self, prefix, **kwargs):
5959
completion = []
6060
if self.allowednames:
6161
if self.directories:
62-
files = _call(["bash", "-c", "compgen -A directory -- '{p}'".format(p=prefix)])
62+
# Using 'bind' in this and the following commands is a workaround to a bug in bash
63+
# that was fixed in bash 5.3 but affects older versions. Environment variables are not treated
64+
# correctly in older versions and calling bind makes them available. For details, see
65+
# https://savannah.gnu.org/support/index.php?111125
66+
files = _call(["bash", "-c", "bind; compgen -A directory -- '{p}'".format(p=prefix)], stderr=subprocess.DEVNULL)
6367
completion += [f + "/" for f in files]
6468
for x in self.allowednames:
65-
completion += _call(["bash", "-c", "compgen -A file -X '!*.{0}' -- '{p}'".format(x, p=prefix)])
69+
completion += _call(["bash", "-c", "bind; compgen -A file -X '!*.{0}' -- '{p}'".format(x, p=prefix)], stderr=subprocess.DEVNULL)
6670
else:
67-
completion += _call(["bash", "-c", "compgen -A file -- '{p}'".format(p=prefix)])
68-
anticomp = _call(["bash", "-c", "compgen -A directory -- '{p}'".format(p=prefix)])
71+
completion += _call(["bash", "-c", "bind; compgen -A file -- '{p}'".format(p=prefix)], stderr=subprocess.DEVNULL)
72+
anticomp = _call(["bash", "-c", "bind; compgen -A directory -- '{p}'".format(p=prefix)], stderr=subprocess.DEVNULL)
6973
completion = list(set(completion) - set(anticomp))
7074

7175
if self.directories:

0 commit comments

Comments
 (0)
0