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

Function uninstallBashCompletion

pkg/cli/shell_completion.go:412–472  ·  view source on GitHub ↗

uninstallBashCompletion uninstalls bash completion

(verbose bool)

Source from the content-addressed store, hash-verified

410
411// uninstallBashCompletion uninstalls bash completion
412func uninstallBashCompletion(verbose bool) error {
413 shellCompletionLog.Print("Uninstalling bash completion")
414
415 homeDir, err := os.UserHomeDir()
416 if err != nil {
417 return fmt.Errorf("failed to get home directory: %w", err)
418 }
419
420 // Check all possible locations where completion might be installed
421 var possiblePaths []string
422
423 // User-level installations
424 possiblePaths = append(possiblePaths, filepath.Join(homeDir, ".bash_completion.d", "gh-aw"))
425
426 // macOS with Homebrew
427 if runtime.GOOS == "darwin" {
428 brewPrefix := os.Getenv("HOMEBREW_PREFIX")
429 if brewPrefix == "" {
430 for _, prefix := range []string{constants.HomebrewPrefix, constants.UsrLocalPrefix} {
431 if fileutil.DirExists(filepath.Join(prefix, "etc", "bash_completion.d")) {
432 possiblePaths = append(possiblePaths, filepath.Join(prefix, "etc", "bash_completion.d", "gh-aw"))
433 }
434 }
435 } else {
436 possiblePaths = append(possiblePaths, filepath.Join(brewPrefix, "etc", "bash_completion.d", "gh-aw"))
437 }
438 }
439
440 // System-wide installations (Linux)
441 if runtime.GOOS == "linux" {
442 possiblePaths = append(possiblePaths, constants.BashCompletionGhAwPath)
443 }
444
445 removed := false
446 var lastErr error
447
448 for _, path := range possiblePaths {
449 if fileutil.FileExists(path) {
450 shellCompletionLog.Printf("Found completion file at: %s", path)
451 if err := os.Remove(path); err != nil {
452 shellCompletionLog.Printf("Failed to remove %s: %v", path, err)
453 lastErr = err
454 continue
455 }
456 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Removed bash completion from: "+path))
457 removed = true
458 }
459 }
460
461 if !removed {
462 return errors.New("no bash completion file found to remove")
463 }
464
465 if lastErr != nil {
466 fmt.Fprintln(os.Stderr, console.FormatWarningMessage("Some completion files could not be removed (may require elevated permissions)"))
467 }
468
469 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Please restart your shell for changes to take effect"))

Calls 9

DirExistsFunction · 0.92
FileExistsFunction · 0.92
FormatSuccessMessageFunction · 0.92
FormatWarningMessageFunction · 0.92
FormatInfoMessageFunction · 0.92
PrintMethod · 0.80
GetenvMethod · 0.80
ErrorfMethod · 0.45
PrintfMethod · 0.45

Tested by 2