diff --git a/pkg/cmd/root/help_topic.go b/pkg/cmd/root/help_topic.go index 59c8b12a3..42892d76d 100644 --- a/pkg/cmd/root/help_topic.go +++ b/pkg/cmd/root/help_topic.go @@ -83,6 +83,9 @@ var HelpTopics = map[string]map[string]string{ "$XDG_CONFIG_HOME/gh" or "$HOME/.config/gh". GH_PROMPT_DISABLED: set to any value to disable interactive prompting in the terminal. + + GH_PATH: set the path to the gh executable, useful for when gh can not properly determine + its own path such as in the cygwin terminal. `), }, "reference": { diff --git a/pkg/cmdutil/factory.go b/pkg/cmdutil/factory.go index e00e1a89a..2d7a73a62 100644 --- a/pkg/cmdutil/factory.go +++ b/pkg/cmdutil/factory.go @@ -34,6 +34,10 @@ type Factory struct { // Executable is the path to the currently invoked binary func (f *Factory) Executable() string { + ghPath := os.Getenv("GH_PATH") + if ghPath != "" { + return ghPath + } if !strings.ContainsRune(f.ExecutableName, os.PathSeparator) { f.ExecutableName = executable(f.ExecutableName) } diff --git a/pkg/cmdutil/factory_test.go b/pkg/cmdutil/factory_test.go index 66b43dda3..eb87ce360 100644 --- a/pkg/cmdutil/factory_test.go +++ b/pkg/cmdutil/factory_test.go @@ -54,3 +54,12 @@ func Test_executable(t *testing.T) { t.Errorf("executable() = %q, want %q", got, bin2Exe) } } + +func Test_Executable_override(t *testing.T) { + override := strings.Join([]string{"C:", "cygwin64", "home", "gh.exe"}, string(os.PathSeparator)) + t.Setenv("GH_PATH", override) + f := Factory{} + if got := f.Executable(); got != override { + t.Errorf("executable() = %q, want %q", got, override) + } +}