File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 55 "fmt"
66 "net/http"
77 "os"
8+ "path/filepath"
9+ "strings"
810
911 "github.com/cli/cli/api"
1012 "github.com/cli/cli/context"
@@ -14,6 +16,7 @@ import (
1416 "github.com/cli/cli/pkg/cmd/extension"
1517 "github.com/cli/cli/pkg/cmdutil"
1618 "github.com/cli/cli/pkg/iostreams"
19+ "github.com/cli/safeexec"
1720)
1821
1922func New (appVersion string ) * cmdutil.Factory {
@@ -114,10 +117,22 @@ func browserLauncher(f *cmdutil.Factory) string {
114117}
115118
116119func executable () string {
117- gh := "gh"
118- if exe , err := os .Executable (); err == nil {
119- gh = exe
120+ exe , _ := os .Executable ()
121+
122+ path := os .Getenv ("PATH" )
123+ for _ , dir := range filepath .SplitList (path ) {
124+ if strings .HasSuffix (dir , "gh" ) {
125+ if dir == exe {
126+ return dir
127+ }
128+ if symlink , _ := os .Readlink (dir ); symlink == exe {
129+ return dir
130+ }
131+ }
120132 }
133+
134+ gh , _ := safeexec .LookPath ("gh" )
135+
121136 return gh
122137}
123138
You can’t perform that action at this time.
0 commit comments