Skip to content

Commit

Permalink
use interactive shells and bind to work around issue in bash
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianPommerening authored Sep 27, 2024
1 parent 4a60a7e commit ad6fa35
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 '-i' and 'bind' in this and the following commands is a workaround to a bug in bash
# that was fixed in bash 3.5 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", "-ic", "bind; compgen -A directory -- '{p}'".format(p=prefix)])
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", "-ic", "bind; compgen -A file -X '!*.{0}' -- '{p}'".format(x, p=prefix)])
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", "-ic", "bind; compgen -A file -- '{p}'".format(p=prefix)])
anticomp = _call(["bash", "-ic", "bind; compgen -A directory -- '{p}'".format(p=prefix)])
completion = list(set(completion) - set(anticomp))

if self.directories:
Expand Down

0 comments on commit ad6fa35

Please sign in to comment.