Skip to content

Commit

Permalink
use interactive shells and bind to work around issue in bash (#506)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
FlorianPommerening authored Dec 31, 2024
1 parent 5c949e9 commit 27e57fb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions argcomplete/completers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ def __call__(self, prefix, **kwargs):
completion = []
if self.allowednames:
if self.directories:
files = _call(["bash", "-c", "compgen -A directory -- '{p}'".format(p=prefix)])
# Using 'bind' in this and the following commands is a workaround to a bug in bash
# that was fixed in bash 5.3 but affects older versions. Environment variables are not treated
# correctly in older versions and calling bind makes them available. For details, see
# https://savannah.gnu.org/support/index.php?111125
files = _call(["bash", "-c", "bind; compgen -A directory -- '{p}'".format(p=prefix)], stderr=subprocess.DEVNULL)
completion += [f + "/" for f in files]
for x in self.allowednames:
completion += _call(["bash", "-c", "compgen -A file -X '!*.{0}' -- '{p}'".format(x, p=prefix)])
completion += _call(["bash", "-c", "bind; compgen -A file -X '!*.{0}' -- '{p}'".format(x, p=prefix)], stderr=subprocess.DEVNULL)
else:
completion += _call(["bash", "-c", "compgen -A file -- '{p}'".format(p=prefix)])
anticomp = _call(["bash", "-c", "compgen -A directory -- '{p}'".format(p=prefix)])
completion += _call(["bash", "-c", "bind; compgen -A file -- '{p}'".format(p=prefix)], stderr=subprocess.DEVNULL)
anticomp = _call(["bash", "-c", "bind; compgen -A directory -- '{p}'".format(p=prefix)], stderr=subprocess.DEVNULL)
completion = list(set(completion) - set(anticomp))

if self.directories:
Expand Down

0 comments on commit 27e57fb

Please sign in to comment.