installPowerShellCompletion installs PowerShell completion
(verbose bool, cmd *cobra.Command)
| 344 | |
| 345 | // installPowerShellCompletion installs PowerShell completion |
| 346 | func installPowerShellCompletion(verbose bool, cmd *cobra.Command) error { |
| 347 | shellCompletionLog.Print("Installing PowerShell completion") |
| 348 | |
| 349 | // Determine PowerShell profile path |
| 350 | var profileCmd *exec.Cmd |
| 351 | if runtime.GOOS == "windows" { |
| 352 | profileCmd = exec.Command("powershell", "-NoProfile", "-Command", "echo $PROFILE") |
| 353 | } else { |
| 354 | profileCmd = exec.Command("pwsh", "-NoProfile", "-Command", "echo $PROFILE") |
| 355 | } |
| 356 | |
| 357 | var profileBuf bytes.Buffer |
| 358 | profileCmd.Stdout = &profileBuf |
| 359 | if err := profileCmd.Run(); err != nil { |
| 360 | return fmt.Errorf("failed to get PowerShell profile path: %w", err) |
| 361 | } |
| 362 | |
| 363 | profilePath := strings.TrimSpace(profileBuf.String()) |
| 364 | |
| 365 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("PowerShell profile path: "+profilePath)) |
| 366 | fmt.Fprintln(os.Stderr, "") |
| 367 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("To enable completions, add the following to your PowerShell profile:")) |
| 368 | fmt.Fprintln(os.Stderr, "") |
| 369 | fmt.Fprintln(os.Stderr, " gh aw completion powershell | Out-String | Invoke-Expression") |
| 370 | fmt.Fprintln(os.Stderr, "") |
| 371 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Or run the following command to append it automatically:")) |
| 372 | fmt.Fprintln(os.Stderr, "") |
| 373 | if runtime.GOOS == "windows" { |
| 374 | fmt.Fprintln(os.Stderr, " gh aw completion powershell >> $PROFILE") |
| 375 | } else { |
| 376 | fmt.Fprintln(os.Stderr, " echo 'gh aw completion powershell | Out-String | Invoke-Expression' >> $PROFILE") |
| 377 | } |
| 378 | fmt.Fprintln(os.Stderr, "") |
| 379 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Then restart your shell or run: . $PROFILE")) |
| 380 | |
| 381 | return nil |
| 382 | } |
| 383 | |
| 384 | // UninstallShellCompletion uninstalls shell completion for the detected shell |
| 385 | func UninstallShellCompletion(verbose bool) error { |
no test coverage detected