You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mkdir files
touch files/aa files/ab
export MY_FILES=$(pwd)/files
./foo.py files/<TAB># This suggests ['files/aa', 'files/ab'] and completes to 'files/a' as expected.
./foo.py $MY_FILES/<TAB># This does not offer any suggestions.
Executing this script fails both in zsh and in bash. The test above only failed in zsh, not in bash but I cannot see how it would succeed in bash if calling the check_call fails. Maybe I only see the correct completions in bash because the command fails and then falls back to the default completion in bash?
Additional Testing in zsh/bash
bash -c "compgen -A file -- '$MY_FILES/'"
Resolves $MY_FILES before the call and effectively calls
bash -c "compgen -A file -- '/path/to/files/'"
and returns
/path/to/files/ab
/path/to/files/aa
This works both in bash and zsh but is not what the FilesCompleter calls and not the completion we expect. We have to escape the $.
bash -c "compgen -A file -- '\$MY_FILES/'"
This doesn't print anything and returns with exit code 1 (both bash and zsh). However, starting a new bash, and then executing compgen -A file -- '\$MY_FILES/' correctly outputs
$MY_FILES/ab
$MY_FILES/aa
I don't understand why bash -c <command> would behave differently from opening a new bash and executing <command> there. I also tried with -i and -l to make the shell interactive, or a login shell with no success. bash -c env also confirmed that $MY_FILES is available in the nested shell.
The text was updated successfully, but these errors were encountered:
When completing a filename that includes an environment variable with the
FilesCompleter
, the forwarding to bash doesn't work.To reproduce
Test environment:
I tested this with the following file
foo.py
Additional Testing in Python
I believe the cause has something to do with the way that
FilesCompleter
forwards the call to bashhttps://github.com/kislyuk/argcomplete/blob/develop/argcomplete/completers.py#L67
I tried to isolate this like this (same setup as above):
Executing this script fails both in zsh and in bash. The test above only failed in zsh, not in bash but I cannot see how it would succeed in bash if calling the
check_call
fails. Maybe I only see the correct completions in bash because the command fails and then falls back to the default completion in bash?Additional Testing in zsh/bash
bash -c "compgen -A file -- '$MY_FILES/'"
Resolves
$MY_FILES
before the call and effectively callsbash -c "compgen -A file -- '/path/to/files/'"
and returns
This works both in bash and zsh but is not what the
FilesCompleter
calls and not the completion we expect. We have to escape the$
.bash -c "compgen -A file -- '\$MY_FILES/'"
This doesn't print anything and returns with exit code 1 (both bash and zsh). However, starting a new bash, and then executing
compgen -A file -- '\$MY_FILES/'
correctly outputsI don't understand why
bash -c <command>
would behave differently from opening a new bash and executing<command>
there. I also tried with-i
and-l
to make the shell interactive, or a login shell with no success.bash -c env
also confirmed that$MY_FILES
is available in the nested shell.The text was updated successfully, but these errors were encountered: