fix(python): complete filenames for script arguments #1018
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ref. ohmybash/oh-my-bash#462
When
[-c command | -m module | file]
is already specified beforecword
, the current implementation of thepython
completer tries to complete filenames as arguments to the command/module/script. However, this doesn't work after an option of the form-?
. The following is a case reported in ohmybash/oh-my-bash#462:The current implementation seems to try to detect the situation by checking the previous and the second previous arguments, but we should explicitly test if
[-c command | -m module | file]
is already specified.Note: Removing an old case pattern that excludes
python
and-?
I think this is actually related to the following line that we once discussed in #952 (see replies [1,2]):
bash-completion/completions/python
Lines 77 to 81 in 8b4db1c
{ => _comp_compgen}_filedir
and_comp_compgen [opts] NAME
#952 (comment){ => _comp_compgen}_filedir
and_comp_compgen [opts] NAME
#952 (comment)After looking at this code again, I now believe this piece of code tried to detect whether the current word is an argument just after
[-c command | -m module | file]
or not. Thecase
pattern and the if statement exclude the case where?(*/)?(micro)python*([0-9.])|?(*/)py@(py|ston)*([0-9.])
),-?
), or${words[cword - 2]} != -[QWX]
).The remaining situation is likely to be only the case where the previous argument is a command/module/script of
[-c command | -m module | file]
. Since we now explicitly check[-c command | -m module | file]
, we should remove this heuristic detection of the first argument.