feat: add shell completions and improve switch UX#111
Conversation
|
Thanks, this looks great overall! A few requests before we move forward:
|
|
Thanks for the review. I addressed the requested follow-up changes in this PR:
I also rechecked the completion flows after the shell-specific updates and pushed the follow-up changes to this same PR. |
Greptile SummaryThis PR adds
Confidence Score: 5/5The change is additive and well-tested; the TUI fixes are conservative and covered by new unit tests. The completion feature is entirely new output code with no shared state; the TUI and switch-picker changes are small, clearly scoped, and exercised by the updated test suite. The only gaps are cosmetic completion omissions (missing src/cli/completion.zig — the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[codex-auth completion] --> B{shell arg?}
B -->|bash| C[writeBashCompletion]
B -->|zsh| D[writeZshCompletion]
B -->|fish| E[writeFishCompletion]
B -->|query| F[parseQuery]
F --> G{target?}
G -->|switch| H[writeSwitchQueryCompletion]
H --> I[loadRegistry]
I --> J[buildDisplayRows]
J --> K[emit number TAB email per account]
C --> L[stdout — static Bash script]
D --> M[stdout — static Zsh script]
E --> N[stdout — static Fish script]
K --> O[stdout — TSV for shell completion]
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
src/cli/completion.zig:115-124
**Zsh switch completions only offer emails, not display numbers**
`_codex_auth_switch_queries` in Zsh stores only the `$description` column (email) and discards `$value` (the display number). Bash includes both columns via `cut -f1` and `cut -f2`, so a Bash user can type `01<TAB>` while a Zsh user cannot. Consider collecting both `nums` and `emails` arrays and passing them both to `compadd`: `compadd -Q -l -- "${nums[@]}" "${emails[@]}"`.
### Issue 2 of 2
src/cli/completion.zig:215
**`app` missing from Fish `__fish_codex_auth_needs_command` guard**
`app` is absent from the sentinel list in `__fish_codex_auth_needs_command`. Because the condition is `not __fish_seen_subcommand_from …`, after a user types `codex-auth app ` and presses Tab, the guard still evaluates to true and Fish presents every top-level command (help, list, login, …) as completions. Additionally, there is no `-a app` entry in the generated script, so `app` cannot be reached via Tab at all. Adding `app` to the `__fish_seen_subcommand_from` list and inserting the corresponding `complete … -n '__fish_codex_auth_needs_command' -a app` entry would fix both gaps. The same omission is present in the Bash `commands` string (line 53) and Zsh `_values 'command'` block (lines 145–156).
Reviews (2): Last reviewed commit: "Merge branch 'main' into feat/fish-compl..." | Re-trigger Greptile |
| \\ switch) | ||
| \\ COMPREPLY=( $(compgen -W "--live --api --skip-api $( _codex_auth_switch_queries | cut -f1 ) $( _codex_auth_switch_queries | cut -f2 )" -- "$cur") ) | ||
| \\ ;; |
There was a problem hiding this comment.
Bash switch completion spawns the binary twice on every Tab press. The
switch case calls _codex_auth_switch_queries once to pipe through cut -f1 and a second time for cut -f2, so codex-auth completion query switch is executed twice per completion attempt. Capturing the output once avoids the double spawn.
| \\ switch) | |
| \\ COMPREPLY=( $(compgen -W "--live --api --skip-api $( _codex_auth_switch_queries | cut -f1 ) $( _codex_auth_switch_queries | cut -f2 )" -- "$cur") ) | |
| \\ ;; | |
| \\ switch) | |
| \\ local _sw_targets | |
| \\ _sw_targets="$(_codex_auth_switch_queries)" | |
| \\ COMPREPLY=( $(compgen -W "--live --api --skip-api $(echo "$_sw_targets" | cut -f1) $(echo "$_sw_targets" | cut -f2)" -- "$cur") ) | |
| \\ ;; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/completion.zig
Line: 80-82
Comment:
Bash switch completion spawns the binary twice on every Tab press. The `switch` case calls `_codex_auth_switch_queries` once to pipe through `cut -f1` and a second time for `cut -f2`, so `codex-auth completion query switch` is executed twice per completion attempt. Capturing the output once avoids the double spawn.
```suggestion
\\ switch)
\\ local _sw_targets
\\ _sw_targets="$(_codex_auth_switch_queries)"
\\ COMPREPLY=( $(compgen -W "--live --api --skip-api $(echo "$_sw_targets" | cut -f1) $(echo "$_sw_targets" | cut -f2)" -- "$cur") )
\\ ;;
```
How can I resolve this? If you propose a fix, please make it concise.
@loongphy/codex-auth-darwin-arm64
@loongphy/codex-auth-darwin-x64
@loongphy/codex-auth-linux-arm64
@loongphy/codex-auth-linux-x64
@loongphy/codex-auth-win32-arm64
@loongphy/codex-auth-win32-x64
@loongphy/codex-auth
commit: |
Summary
codex-auth completion <shell>cxalias from the package and docsDetails
completion bash,completion zsh, andcompletion fishcxnpm binary alias and related docs/examplesEscexit handling and arrow-key navigationValidation
HOME=/tmp/codex-auth-pr-update ZIG_GLOBAL_CACHE_DIR=/tmp/codex-auth-pr-update/zig-global-cache ZIG_LOCAL_CACHE_DIR=/tmp/codex-auth-pr-update/zig-local-cache zig build run -- listScreenshots
Fish command completion
Fish switch suggestions
Bash switch suggestions
Zsh command completion
Zsh switch suggestions