Skip to content

fix(completions): install bash completions into all login + non-login rc files#288

Closed
sachiniyer wants to merge 2 commits intomainfrom
siyer/fix-bash-completions-login
Closed

fix(completions): install bash completions into all login + non-login rc files#288
sachiniyer wants to merge 2 commits intomainfrom
siyer/fix-bash-completions-login

Conversation

@sachiniyer
Copy link
Copy Markdown
Contributor

Summary

  • rc_path for bash picked a single rc file (preferring .bashrc), but bash login shells read .bash_profile / .bash_login instead — so on macOS Terminal and SSH setups where both files exist, completions never loaded in login shells.
  • Mirror rustup: append the snippet to every existing bash rc file (.bash_profile, .bash_login, .bashrc), creating .bashrc if none exist. Each file is checked independently for the snippet and skipped if already present, so re-runs and partial installs converge.
  • Factored installation into a small install_snippet helper and bash_rc_paths helper so the per-file idempotency and the bash file-selection logic are unit-testable.

Fixes #267.

Test plan

  • cargo fmt --check
  • cargo clippy -- -D warnings (matches CI)
  • cargo test --lib — 298 passed, including new cases:
    • bash_rc_paths_only_bashrc
    • bash_rc_paths_only_bash_profile
    • bash_rc_paths_both_exist
    • bash_rc_paths_all_three_exist
    • bash_rc_paths_neither_exists_creates_bashrc
    • install_snippet_appends_to_new_file
    • install_snippet_preserves_existing_content
    • install_snippet_is_idempotent
    • install_snippet_per_file_idempotency_across_bash_rcs

🤖 Generated with Claude Code

… rc files

Bash login shells read .bash_profile (or .bash_login), not .bashrc. The
previous logic preferred .bashrc when it existed, so on macOS Terminal
and SSH setups where both files are present, completions never loaded
in login shells.

Mirror rustup's approach: append the snippet to every existing bash rc
file (.bash_profile, .bash_login, .bashrc), creating .bashrc if none
exist. Each file is written independently and skipped when the snippet
is already present, so re-runs and partial installs converge.

Fixes #267.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sachiniyer sachiniyer temporarily deployed to integration-tests May 9, 2026 03:06 — with GitHub Actions Inactive
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sachiniyer sachiniyer temporarily deployed to integration-tests May 9, 2026 03:18 — with GitHub Actions Inactive
@sachiniyer
Copy link
Copy Markdown
Contributor Author

Closing — taking a different approach. Rather than a multi-file dotfile installer (rustup-style), we're going to switch detail completions to the print-and-source pattern that kubectl, gh, terraform, etc. use: emit the completion script to stdout, document source <(detail completions bash). That sidesteps the rc-file-discovery question entirely and matches user expectations from other CLIs. Will open a follow-up PR addressing #267 with that approach.

@sachiniyer sachiniyer closed this May 9, 2026
sachiniyer added a commit that referenced this pull request May 9, 2026
…iles (#293)

## 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.
- Users wire it up however they want — e.g. `source <(detail completions
bash)` in `.bashrc`, or copy the line into `.bash_profile` for login
shells. This sidesteps the .bashrc-vs-.bash_profile login-shell question
entirely (issue #267).
- Same pattern as `kubectl completion`, `gh completion`, `terraform
-install-autocomplete` peers — well-trodden territory and easy to
document.
- `SHELL` is an optional positional arg; default is still auto-detected
from `$SHELL`. Supported shells unchanged: bash, zsh, fish, elvish,
powershell.
- `Completions` is now `is_silent() == true` so the auto-update notice
on stderr doesn't fire every time a shell rc file evaluates `source
<(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 completions` and it appended a `# Detail
CLI shell completions` block to your rc file, you can leave it in place
(the snippet is identical) or delete it and re-wire via `source <(detail
completions bash)` instead.

## Test plan
- [x] `cargo fmt --check`
- [x] `cargo clippy -- -D warnings` (matches CI)
- [x] `cargo test` — 290 lib + 18 integration passing, including new
`print_snippet_*` tests and the `silent_for_completions` /
`completions_*shell_arg` parser tests
- [x] `cargo xtask check-help` — `docs/HELP.md` regenerated and in sync
- [x] Manual: `cargo run -- completions bash` prints `eval
"\$(COMPLETE=bash detail 2>/dev/null)"` to stdout

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] CLI Completions: Bash login shells don't load installed completions when both .bashrc and .bash_profile exist

1 participant