Skip to content

init: detect package-installed shell completions#25

Open
murrayju wants to merge 1 commit into
mainfrom
murrayju/init-detect-package-completions
Open

init: detect package-installed shell completions#25
murrayju wants to merge 1 commit into
mainfrom
murrayju/init-detect-package-completions

Conversation

@murrayju
Copy link
Copy Markdown
Member

@murrayju murrayju commented Jun 3, 2026

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.), but ghost init was 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) in internal/common/shell_setup.go that probes the well-known package paths:

  • Homebrew — resolved via $HOMEBREW_PREFIX when set, with fallback to the canonical /opt/homebrew, /usr/local, and /home/linuxbrew/.linuxbrew prefixes.
  • deb/rpm — the system paths under /usr/share/... defined in .goreleaser.yaml are always checked.

detectCompletionsState and runInitCompletions now consult that helper before falling back to the rc-mention check. When a package install is found, the menu shows already installed at <path> and the live run prints Completions already installed at <path>. instead of writing to the rc file.

Before

[x] 4. Shell completions    not configured (would write to ~/.bashrc)

After (with brew-installed ghost)

[ ] 4. Shell completions    already installed at /opt/homebrew/etc/bash_completion.d/ghost

Tests

  • Added TestPackageInstalledCompletionPath covering bash/zsh/fish Homebrew detection, unsupported shells, and the no-file case.
  • Pinned HOMEBREW_PREFIX to an empty temp dir in TestRunSelectedInitSteps_ConfiguresPathBeforeCompletions so a brew-installed completion on the dev machine can't cause the test to skip the snippet write.

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.
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.

1 participant