MCPcopy Create free account
hub / github.com/github/gh-aw / installFishCompletion

Function installFishCompletion

pkg/cli/shell_completion.go:307–343  ·  view source on GitHub ↗

installFishCompletion installs fish completion

(verbose bool, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

305
306// installFishCompletion installs fish completion
307func installFishCompletion(verbose bool, cmd *cobra.Command) error {
308 shellCompletionLog.Print("Installing fish completion")
309
310 // Generate completion script using Cobra
311 var buf bytes.Buffer
312 if err := cmd.GenFishCompletion(&buf, true); err != nil {
313 return fmt.Errorf("failed to generate fish completion: %w", err)
314 }
315
316 completionScript := buf.String()
317
318 // Determine installation path
319 homeDir, err := os.UserHomeDir()
320 if err != nil {
321 return fmt.Errorf("failed to get home directory: %w", err)
322 }
323
324 // Fish completion directory
325 completionDir := filepath.Join(homeDir, ".config", "fish", "completions")
326 // Use restrictive permissions (0750) following principle of least privilege
327 if err := os.MkdirAll(completionDir, constants.DirPermSensitive); err != nil {
328 return fmt.Errorf("failed to create completion directory: %w", err)
329 }
330
331 completionPath := filepath.Join(completionDir, "gh-aw.fish")
332
333 // Write completion file
334 // Use restrictive permissions (0600) following principle of least privilege
335 if err := os.WriteFile(completionPath, []byte(completionScript), constants.FilePermSensitive); err != nil {
336 return fmt.Errorf("failed to write completion file: %w", err)
337 }
338
339 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Installed fish completion to: "+completionPath))
340 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Fish will automatically load completions on next shell start"))
341
342 return nil
343}
344
345// installPowerShellCompletion installs PowerShell completion
346func installPowerShellCompletion(verbose bool, cmd *cobra.Command) error {

Callers 1

InstallShellCompletionFunction · 0.85

Calls 6

FormatSuccessMessageFunction · 0.92
FormatInfoMessageFunction · 0.92
PrintMethod · 0.80
GenFishCompletionMethod · 0.80
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected