feat(cli): one-command shell completion install (completions --install)#20
Merged
Conversation
`codegraph completions <shell> --install` writes the generated script to
the shell's standard completion location instead of only printing it, and
prints a restart hint. Without --install the behavior is unchanged (stdout).
PowerShell emits `using namespace System.Management.Automation` on its first
lines, and PowerShell only accepts `using` at the start of a script. Appending
the output to a non-empty $PROFILE therefore fails with
UsingMustBeAtStartOfScript and, on repeat, leaves a duplicate block. The fix
writes the PowerShell script to its own completion.ps1 (where `using` is legal
at file start) under %LOCALAPPDATA%\codegraph and adds a single idempotent
dot-source line to $PROFILE (check-before-append, never duplicated).
bash/zsh/fish/elvish are written into their standard completion dirs
(${XDG_DATA_HOME:-~/.local/share}/bash-completion/completions/codegraph,
~/.zfunc/_codegraph, ~/.config/fish/completions/codegraph.fish,
~/.config/codegraph/completion.elv); zsh/elvish print a one-time manual
loading hint, no rc files are edited automatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make shell completions actually usable in one command.
codegraph completions <shell>previously only printed the script to stdout, leaving users to hand-wire their rc/profile — which on PowerShell is actively broken (clap_complete emitsusing namespace ...at the top, so appending it into a non-empty$PROFILEfails withUsingMustBeAtStartOfScript, and re-appending duplicates it).completions <shell> --install— writes the completion script to the shell's standard location and reports the path. Idempotent (safe to re-run). Without--install, behavior is unchanged (stdout).${XDG_DATA_HOME:-~/.local/share}/bash-completion/completions/codegraph(auto-loaded, no.bashrcedit)~/.zfunc/_codegraph(+ advisesfpath+=~/.zfunc)~/.config/fish/completions/codegraph.fish%LOCALAPPDATA%\codegraph\completion.ps1(a separate file sousing namespaceis legal at file start) + a single idempotent dot-source line in$PROFILE~/.config/codegraph/completion.elv(+ adviseseval)docs/cli.mdexpanded with per-shell enablement (--install+ manual fallback), the PowerShellusing/UsingMustBeAtStartOfScriptrationale, and theCtrl+Space/Set-PSReadLineKeyHandler -Key Tab -Function MenuCompletetip; concise zh-CN mirror; one-line README pointer.Verification
cargo test -p codegraph-rsgreen incl. newcompletions_powershell_install_is_idempotent+completions_bash_install_writes_file.--install×3 → exactly one dot-source line in$PROFILE; bash--install×2 → one completion file,.bashrcuntouched.cargo clippy --workspace --all-targets -- -D warningsclean;cargo fmt --all --check+make fmtclean;bash scripts/guardrail.shexit 0.Note
CI may flake on two pre-existing parallel tests (
codegraph-watch::sync::tests::unchanged_file_hash_is_not_reindexed,codegraph-mcp::golden_mcp::tools_list_matches_upstream_names_and_schemas) — re-run if so; not introduced here.