mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 20:09:39 -08:00
feat(cygwin): better detection
This commit is contained in:
parent
6f30788a16
commit
f9d2f6040e
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue