-
-
Notifications
You must be signed in to change notification settings - Fork 2
fix(setup): auto-configure zsh fpath for shell completions #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8a22867
c580592
106adc4
72e30c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,11 @@ import { | |
| import { CommandOutput } from "../../lib/formatters/output.js"; | ||
| import { logger } from "../../lib/logger.js"; | ||
| import { | ||
| addToFpath, | ||
| addToGitHubPath, | ||
| addToPath, | ||
| detectShell, | ||
| getFpathCommand, | ||
| getPathCommand, | ||
| isBashAvailable, | ||
| isInPath, | ||
|
|
@@ -180,6 +182,37 @@ async function tryBashCompletionFallback( | |
| return await installCompletions("bash", homeDir, xdgDataHome); | ||
| } | ||
|
|
||
| /** | ||
| * Ensure the zsh completion directory is in fpath. | ||
| * | ||
| * Runs even on updates so existing installs get fpath configured (one-time migration). | ||
| * Returns status messages for the user. | ||
| */ | ||
| async function handleZshFpath( | ||
| shell: ShellInfo, | ||
| completionDir: string, | ||
| isNewInstall: boolean | ||
| ): Promise<string[]> { | ||
| const lines: string[] = []; | ||
|
|
||
| if (shell.configFile) { | ||
| const result = await addToFpath(shell.configFile, completionDir); | ||
| if (result.modified) { | ||
| lines.push(`Completions: ${result.message}`); | ||
| lines.push(` Restart your shell or run: source ${shell.configFile}`); | ||
| } else if (result.manualCommand) { | ||
| lines.push(`Completions: ${result.message}`); | ||
| lines.push( | ||
| ` Add manually to ${shell.configFile}: ${result.manualCommand}` | ||
| ); | ||
| } | ||
| } else if (isNewInstall) { | ||
| lines.push(` Add to your .zshrc: ${getFpathCommand(completionDir)}`); | ||
| } | ||
|
|
||
| return lines; | ||
| } | ||
|
|
||
| /** | ||
| * Handle shell completion installation. | ||
| * | ||
|
|
@@ -200,20 +233,19 @@ async function handleCompletions( | |
| const location = await installCompletions(shell.type, homeDir, xdgDataHome); | ||
|
|
||
| if (location) { | ||
| // Silently updated — no need to tell the user on every upgrade | ||
| if (!location.created) { | ||
| return []; | ||
| } | ||
|
|
||
| const lines = [`Completions: Installed to ${location.path}`]; | ||
| const lines: string[] = []; | ||
|
|
||
| // Zsh may need fpath hint | ||
| if (shell.type === "zsh") { | ||
| const completionDir = dirname(location.path); | ||
| lines.push( | ||
| ` You may need to add to .zshrc: fpath=(${completionDir} $fpath)` | ||
| ...(await handleZshFpath(shell, completionDir, location.created)) | ||
| ); | ||
| } | ||
|
|
||
|
Comment on lines
242
to
+244
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: On upgrade, Suggested FixModify Prompt for AI Agent |
||
| if (location.created) { | ||
| lines.unshift(`Completions: Installed to ${location.path}`); | ||
| } | ||
|
|
||
| return lines; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.