Skip to content

Commit 2dba58b

Browse files
author
wilso199
committed
Using gh executable from PATH in favor of the resolved path
1 parent e6ff77c commit 2dba58b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

pkg/cmd/factory/default.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
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

1922
func New(appVersion string) *cmdutil.Factory {
@@ -114,10 +117,22 @@ func browserLauncher(f *cmdutil.Factory) string {
114117
}
115118

116119
func 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

0 commit comments

Comments
 (0)