installFishCompletion installs fish completion
(verbose bool, cmd *cobra.Command)
| 305 | |
| 306 | // installFishCompletion installs fish completion |
| 307 | func 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 |
| 346 | func installPowerShellCompletion(verbose bool, cmd *cobra.Command) error { |
no test coverage detected