Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ZSH implementation - missing completion (kislyuk#433)
* Fix ZSH implementation - missing completion Initially, `COMP_WORDS` was employed for matching modules and interpreter arguments. However, `COMP_WORDS` isn't defined in ZSH; `words` is the correct variable to use instead. To resolve this, an argument vector with base-1 indexing was created to work with both shells. Secondly, the __python_argcomplete_scan_head function included a defective read command in ZSH during interpreter matching. Using -k with read in ZSH reads a specified num of bytes, regardless of a newline presence. This issue was addressed by introducing a secondary read command in both shells to retrieve the line. Additionally, in ZSH, regex matches are not stored in BASH_REMATCH unless a compatibility option is activated. This was addressed by enabling this option locally. The difference between base-0 and base-1 indexing was mitigated by incrementing `BASH_REMATCH` when operating in Bash and indexing correctly. A ZSH-compatible version of __python_argcomplete_expand_tilde_by_ref was also introduced as the prior version utilized zero indexing and Bash-specific indirection syntax. Moreover, the indexing and variable expansion of the argument array in the `__python_argcomplete_run` function were correctly adjusted. Lastly, the path to a Python script was expanded using tilde notation to enable auto-completion when employing: ```zsh python ~/some/script.py ``` * FIX: missing bash_completion.d -> Darwin install (kislyuk#431) When installing the global completion script, the non-existence of the `/etc/bash_completion.d` directory mistakenly led argcomplete to install the completion scripts in `/usr/local/etc/bash_completion.d`. This directory is the default location on MacOS and is not typically sourced by Linux distributions. * Global completion for Bash 5.0 and ZSH 5.7 This commit introduces several changes to ensure compatibility with older environments. One significant modification was made to address an issue with `BASH_REMATCH` in older versions of Bash. In these versions, modifying `BASH_REMATCH` would cause the script to silently exit. To prevent this, a new local variable named `_BASH_REMATCH` has been defined to hold the shifted match values. Another problem identified was that the secondary capture group, which previously identified the interpreter, did not capture the version of the Python interpreter within the regex. For example, it didn't capture `python3` or `python3.9`. This resulted in the incorrect interpreter being used. To resolve this, I decided to use the previous capture string, which captures the entire grouping after the shebang. With this change, interpreter lines like `/bin/env pythonX` will work correctly with the new implementation. Additionally, the `describe` command, `_describe "$executable" completions -o nosort`, produced some incorrect suggestions on `zsh 5.7`. To rectify this, I removed the `-o nosort` option, which appeared to fix the issue and restore the expected behavior.
- Loading branch information