feat(completions): print snippet to stdout instead of writing to dotfiles#293
Conversation
…iles Switch `detail completions [SHELL]` to the kubectl/gh print-and-source pattern: emit the eval/source line on stdout and exit. Users wire it up wherever they actually source dotfiles, which sidesteps the .bashrc-vs-.bash_profile login/non-login shell problem entirely. - Drop file-writing logic (rc_path, parent dir creation, idempotency check, "installed in <file>" success message). - Add optional positional SHELL arg; default still auto-detects $SHELL. - Mark Completions silent so the auto-update notice on stderr does not surface every time a shell rc file does `source <(detail completions bash)`. - Replace file-system tests with a Writer-based print_snippet helper. Closes #267. Supersedes #288. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/commands/completions.rs">
<violation number="1" location="src/commands/completions.rs:110">
P2: This test mutates the global `SHELL` environment variable without synchronization, which can race with other tests and cause flaky results in parallel test runs.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e9f87cd89
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// Add `source <(detail completions bash)` to your shell rc file | ||
| /// (.bashrc, .zshrc, etc.) to enable tab completion. SHELL defaults |
There was a problem hiding this comment.
Correct the cross-shell completion example
This help text tells users to add the bash-specific invocation to any rc file, including .zshrc; in a zsh/fish/powershell setup that command still prints the bash activation snippet (COMPLETE=bash), so users following the generated help install the wrong completion script or a syntax that their shell cannot source. Please make the example shell-specific or use the auto-detected form where appropriate.
Useful? React with 👍 / 👎.
- Move shell auto-detection out of `print_snippet` and into `handle()` so the helper is purely deterministic. Drops the racy `print_snippet_uses_detected_shell_when_none` test that mutated $SHELL in parallel with `detect_shell_from_env`. (cubic P2) - Replace the misleading "add `source <(detail completions bash)` to any rc file" example with shell-specific lines for bash, zsh, fish, and powershell so a zsh user can't accidentally source the bash snippet. Switch to a `long_about` constant since clap collapses line breaks inside doc-comment paragraphs. (codex P2) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Addressed both review comments in 127e4a8: cubic (P2, completions.rs:110) — agreed, fixed. The new codex (P2, lib.rs:147) — agreed, fixed. The old example mixed
|
Summary
detail completions [SHELL]now prints the activation snippet (eval .../source <(...)/ etc.) to stdout and exits, instead of appending it to a chosen rc file.source <(detail completions bash)in.bashrc, or copy the line into.bash_profilefor login shells. This sidesteps the .bashrc-vs-.bash_profile login-shell question entirely (issue [Detail Bug] CLI Completions: Bash login shells don't load installed completions when both .bashrc and .bash_profile exist #267).kubectl completion,gh completion,terraform -install-autocompletepeers — well-trodden territory and easy to document.SHELLis an optional positional arg; default is still auto-detected from$SHELL. Supported shells unchanged: bash, zsh, fish, elvish, powershell.Completionsis nowis_silent() == trueso the auto-update notice on stderr doesn't fire every time a shell rc file evaluatessource <(detail completions bash)at startup.Closes #267. Supersedes #288 (which tried a rustup-style multi-file install — closed in favour of this simpler pattern).
Migration
If you previously ran
detail completionsand it appended a# Detail CLI shell completionsblock to your rc file, you can leave it in place (the snippet is identical) or delete it and re-wire viasource <(detail completions bash)instead.Test plan
cargo fmt --checkcargo clippy -- -D warnings(matches CI)cargo test— 290 lib + 18 integration passing, including newprint_snippet_*tests and thesilent_for_completions/completions_*shell_argparser testscargo xtask check-help—docs/HELP.mdregenerated and in synccargo run -- completions bashprintseval "\$(COMPLETE=bash detail 2>/dev/null)"to stdout🤖 Generated with Claude Code