Finds the location of the executable for the current process as it's found in PATH, respecting symlinks. If the process couldn't determine its location, return fallbackName. If the executable wasn't found in PATH, return the absolute location to the program. The idea is that the result of this func
(fallback string)
| 439 | // auth login`, running `brew update` will print out authentication errors as git is unable to locate |
| 440 | // Homebrew-installed `gh` |
| 441 | func executable(fallback string) string { |
| 442 | exe, err := os.Executable() |
| 443 | if err != nil { |
| 444 | return fallback |
| 445 | } |
| 446 | |
| 447 | base := filepath.Base(exe) |
| 448 | path := os.Getenv("PATH") |
| 449 | for _, dir := range filepath.SplitList(path) { |
| 450 | p, err := filepath.Abs(filepath.Join(dir, base)) |
| 451 | if err != nil { |
| 452 | continue |
| 453 | } |
| 454 | f, err := os.Lstat(p) |
| 455 | if err != nil { |
| 456 | continue |
| 457 | } |
| 458 | |
| 459 | if p == exe { |
| 460 | return p |
| 461 | } else if f.Mode()&os.ModeSymlink != 0 { |
| 462 | realP, err := filepath.EvalSymlinks(p) |
| 463 | if err != nil { |
| 464 | continue |
| 465 | } |
| 466 | realExe, err := filepath.EvalSymlinks(exe) |
| 467 | if err != nil { |
| 468 | continue |
| 469 | } |
| 470 | if realP == realExe { |
| 471 | return p |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | return exe |
| 477 | } |
| 478 | |
| 479 | func mightBeGHESUser(cfg gh.Config) bool { |
| 480 | if os.Getenv("GH_ENTERPRISE_TOKEN") != "" || os.Getenv("GITHUB_ENTERPRISE_TOKEN") != "" { |