Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(_comp_count_args): check optarg correctly
When the current implementation checks an option argument, it tests whether the previous word matches $2 (i.e., a pattern of options taking an option argument). This implementation has multiple issues: * When the options taking an option argument does not start with `-`, the option is counted as an independent argument. For example, `ssh` completion passes `@(-c|[-+]o)` as $2, but `+o` is counted as an argument with the current implementation. * An option argument that looks like an option taking an option argument can prevent the next word counted as an argument. For example, when `cmd -o -o arg` is processed with $2 being `-o`, the second `-o` should be treated as an option argument and `arg` should be counted as an argument. However, with the current implementation, `arg` is not counted because the previous word `-o` matches the pattern. * When `cmd -o -- -x` is processed with $2 being `-o`, `--` should be treated as an option argument so should lose its special meaning, and `-x` is still treated as an option. However, with the current implementation, `--` does not lose its special meaning, so `-x` is unexpectedly treated as an argument. * Also, with the current implementation, when $2 is not specified, an argument after an empty word is not counted as an argument because $2 matches the empty word, (though Readline usually do not store an empty word in COMP_WORDS). This patch fixes those issues by changing how options taking an option argument are processed.
- Loading branch information