init: detect package-installed shell completions#25
Open
murrayju wants to merge 1 commit into
Open
Conversation
When ghost is installed via a package manager (Homebrew, deb, rpm), the completion files are already placed in shell-loaded directories, but 'ghost init' would still offer to append a sourcing snippet to the user's rc file. Probe those well-known package paths and treat the completions step as already configured when one is found. Homebrew's prefix is resolved via $HOMEBREW_PREFIX (with fallback to the canonical /opt/homebrew, /usr/local, and /home/linuxbrew/.linuxbrew locations); the deb/rpm system paths under /usr/share are always checked.
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.
Fixes TNT-95.
When ghost is installed via a package manager (Homebrew, deb, rpm), the completion files are already placed in shell-loaded directories (e.g.
/opt/homebrew/etc/bash_completion.d/ghost,/usr/share/zsh/vendor-completions/_ghost, etc.), butghost initwas still offering to append a sourcing snippet to the user's rc file because it only checked for the snippet in the rc file.This PR adds
PackageInstalledCompletionPath(shell)ininternal/common/shell_setup.gothat probes the well-known package paths:$HOMEBREW_PREFIXwhen set, with fallback to the canonical/opt/homebrew,/usr/local, and/home/linuxbrew/.linuxbrewprefixes./usr/share/...defined in.goreleaser.yamlare always checked.detectCompletionsStateandrunInitCompletionsnow consult that helper before falling back to the rc-mention check. When a package install is found, the menu showsalready installed at <path>and the live run printsCompletions already installed at <path>.instead of writing to the rc file.Before
After (with brew-installed ghost)
Tests
TestPackageInstalledCompletionPathcovering bash/zsh/fish Homebrew detection, unsupported shells, and the no-file case.HOMEBREW_PREFIXto an empty temp dir inTestRunSelectedInitSteps_ConfiguresPathBeforeCompletionsso a brew-installed completion on the dev machine can't cause the test to skip the snippet write.