feat(cygwin): better detection

This commit is contained in:
Jan De Dobbeleer 2024-07-25 06:47:33 +02:00 committed by Jan De Dobbeleer
parent 6f30788a16
commit f9d2f6040e
6 changed files with 26 additions and 4 deletions

View file

@ -172,6 +172,11 @@ func (env *Environment) IsWsl2() bool {
return args.Bool(0)
}
func (env *Environment) IsCygwin() bool {
args := env.Called()
return args.Bool(0)
}
func (env *Environment) TerminalWidth() (int, error) {
args := env.Called()
return args.Int(0), args.Error(1)

View file

@ -175,6 +175,7 @@ type Environment interface {
HTTPRequest(url string, body io.Reader, timeout int, requestModifiers ...http.RequestModifier) ([]byte, error)
IsWsl() bool
IsWsl2() bool
IsCygwin() bool
StackCount() int
TerminalWidth() (int, error)
CachePath() string
@ -264,9 +265,13 @@ func (term *Terminal) resolveConfigPath() {
return
}
isCygwin := func() bool {
return term.Platform() == WINDOWS && len(term.Getenv("OSTYPE")) > 0
}
// Cygwin path always needs the full path as we're on Windows but not really.
// Doing filepath actions will convert it to a Windows path and break the init script.
if term.Platform() == WINDOWS && term.Shell() == "bash" {
if isCygwin() {
term.Debug("Cygwin detected, using full path for config")
return
}

View file

@ -53,6 +53,11 @@ func (term *Terminal) IsWsl2() bool {
return strings.Contains(uname, "WSL2")
}
func (term *Terminal) IsCygwin() bool {
defer term.Trace(time.Now())
return false
}
func (term *Terminal) TerminalWidth() (int, error) {
defer term.Trace(time.Now())

View file

@ -87,6 +87,11 @@ func (term *Terminal) IsWsl2() bool {
return false
}
func (term *Terminal) IsCygwin() bool {
defer term.Trace(time.Now())
return len(term.Getenv("OSTYPE")) > 0
}
func (term *Terminal) TerminalWidth() (int, error) {
defer term.Trace(time.Now())

View file

@ -126,8 +126,7 @@ func (pt *Path) setPaths() {
return false
}
isCygwin := pt.env.GOOS() == runtime.WINDOWS && pt.env.Shell() == shell.BASH
return isCygwin
return pt.env.IsCygwin()
}
pt.cygPath = displayCygpath()

View file

@ -180,6 +180,7 @@ func TestAgnosterPathStyles(t *testing.T) {
MaxDepth int
MaxWidth int
HideRootLocation bool
Cygwin bool
}{
{
Style: Unique,
@ -431,6 +432,7 @@ func TestAgnosterPathStyles(t *testing.T) {
Pwd: "C:\\Users\\foo\\foobar\\man",
GOOS: runtime.WINDOWS,
Shell: shell.BASH,
Cygwin: true,
Cygpath: "/c/Users/foo/foobar/man",
PathSeparator: "\\",
FolderSeparatorIcon: " > ",
@ -766,6 +768,7 @@ func TestAgnosterPathStyles(t *testing.T) {
env.On("Home").Return(tc.HomePath)
env.On("Pwd").Return(tc.Pwd)
env.On("GOOS").Return(tc.GOOS)
env.On("IsCygwin").Return(tc.Cygwin)
env.On("StackCount").Return(0)
env.On("IsWsl").Return(false)
args := &runtime.Flags{
@ -780,7 +783,7 @@ func TestAgnosterPathStyles(t *testing.T) {
env.On("DebugF", testify_.Anything, testify_.Anything).Return(nil)
displayCygpath := tc.GOOS == runtime.WINDOWS && tc.Shell == shell.BASH
displayCygpath := tc.Cygwin
if displayCygpath {
env.On("RunCommand", "cygpath", []string{"-u", tc.Pwd}).Return(tc.Cygpath, tc.CygpathError)
env.On("RunCommand", "cygpath", testify_.Anything).Return("brrrr", nil)