diff options
| author | ilikepugs <[email protected]> | 2026-05-12 16:52:34 +0300 |
|---|---|---|
| committer | ilikepugs <[email protected]> | 2026-05-12 17:47:32 +0300 |
| commit | 6ea40e24c5763afe5f4abc6fcabf2cd700799cc2 (patch) | |
| tree | 0d6dc33289e56478bdd7345f907d97f231bebf17 /library/cpp | |
| parent | d4e2776cb1e96d45483cdb79d17312206d28e162 (diff) | |
make zsh completion works with first Tab
### Как сейчас
1. zsh подгружает `~/.zfunc/_<command>`, выполняет его как тело функции `_<command>`.
2. Это тело состоит только из определения `_<command>() { ... }` и helper'ов — оно переопределяет `_<command>`, но не вызывает новое определение.
3. Тело завершилось, ни одного `compadd` не было — completion ничего не выдал.
При втором TAB вызывается уже переопределённый "настоящий" `_<command>` — и тогда дополнение работает.
\--
### Что сделал
Добавил вызов `_<command>` в конец скрипта, так что теперь вызов переопределнного `_<command>` происходит на первом `Tab`.
commit_hash:9f60240a3c3d85088101570156c8bde18bf0792a
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/getopt/small/completion_generator.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/library/cpp/getopt/small/completion_generator.cpp b/library/cpp/getopt/small/completion_generator.cpp index d893afb40a9..5e0e55ed38b 100644 --- a/library/cpp/getopt/small/completion_generator.cpp +++ b/library/cpp/getopt/small/completion_generator.cpp @@ -63,6 +63,14 @@ namespace NLastGetopt { L; manager.GenerateZsh(out); + // When the completion file is autoloaded by `compinit` from `$fpath`, + // zsh treats the file content as the body of function `_<command>`. + // On first invocation that body merely (re)defines `_<command>` and + // its helpers, so completion would not actually run until the second + // TAB. Calling the redefined function here makes it work on the very + // first TAB and is also harmless when the script is `source`d. + L << "_" << command << " \"$@\""; + out.Print(stream); } |
