mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-29 04:49: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)
|
return args.Bool(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (env *Environment) IsCygwin() bool {
|
||||||
|
args := env.Called()
|
||||||
|
return args.Bool(0)
|
||||||
|
}
|
||||||
|
|
||||||
func (env *Environment) TerminalWidth() (int, error) {
|
func (env *Environment) TerminalWidth() (int, error) {
|
||||||
args := env.Called()
|
args := env.Called()
|
||||||
return args.Int(0), args.Error(1)
|
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)
|
HTTPRequest(url string, body io.Reader, timeout int, requestModifiers ...http.RequestModifier) ([]byte, error)
|
||||||
IsWsl() bool
|
IsWsl() bool
|
||||||
IsWsl2() bool
|
IsWsl2() bool
|
||||||
|
IsCygwin() bool
|
||||||
StackCount() int
|
StackCount() int
|
||||||
TerminalWidth() (int, error)
|
TerminalWidth() (int, error)
|
||||||
CachePath() string
|
CachePath() string
|
||||||
|
@ -264,9 +265,13 @@ func (term *Terminal) resolveConfigPath() {
|
||||||
return
|
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.
|
// 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.
|
// 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")
|
term.Debug("Cygwin detected, using full path for config")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,11 @@ func (term *Terminal) IsWsl2() bool {
|
||||||
return strings.Contains(uname, "WSL2")
|
return strings.Contains(uname, "WSL2")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (term *Terminal) IsCygwin() bool {
|
||||||
|
defer term.Trace(time.Now())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (term *Terminal) TerminalWidth() (int, error) {
|
func (term *Terminal) TerminalWidth() (int, error) {
|
||||||
defer term.Trace(time.Now())
|
defer term.Trace(time.Now())
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,11 @@ func (term *Terminal) IsWsl2() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (term *Terminal) IsCygwin() bool {
|
||||||
|
defer term.Trace(time.Now())
|
||||||
|
return len(term.Getenv("OSTYPE")) > 0
|
||||||
|
}
|
||||||
|
|
||||||
func (term *Terminal) TerminalWidth() (int, error) {
|
func (term *Terminal) TerminalWidth() (int, error) {
|
||||||
defer term.Trace(time.Now())
|
defer term.Trace(time.Now())
|
||||||
|
|
||||||
|
|
|
@ -126,8 +126,7 @@ func (pt *Path) setPaths() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
isCygwin := pt.env.GOOS() == runtime.WINDOWS && pt.env.Shell() == shell.BASH
|
return pt.env.IsCygwin()
|
||||||
return isCygwin
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pt.cygPath = displayCygpath()
|
pt.cygPath = displayCygpath()
|
||||||
|
|
|
@ -180,6 +180,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
MaxDepth int
|
MaxDepth int
|
||||||
MaxWidth int
|
MaxWidth int
|
||||||
HideRootLocation bool
|
HideRootLocation bool
|
||||||
|
Cygwin bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Style: Unique,
|
Style: Unique,
|
||||||
|
@ -431,6 +432,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
Pwd: "C:\\Users\\foo\\foobar\\man",
|
Pwd: "C:\\Users\\foo\\foobar\\man",
|
||||||
GOOS: runtime.WINDOWS,
|
GOOS: runtime.WINDOWS,
|
||||||
Shell: shell.BASH,
|
Shell: shell.BASH,
|
||||||
|
Cygwin: true,
|
||||||
Cygpath: "/c/Users/foo/foobar/man",
|
Cygpath: "/c/Users/foo/foobar/man",
|
||||||
PathSeparator: "\\",
|
PathSeparator: "\\",
|
||||||
FolderSeparatorIcon: " > ",
|
FolderSeparatorIcon: " > ",
|
||||||
|
@ -766,6 +768,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
env.On("Home").Return(tc.HomePath)
|
env.On("Home").Return(tc.HomePath)
|
||||||
env.On("Pwd").Return(tc.Pwd)
|
env.On("Pwd").Return(tc.Pwd)
|
||||||
env.On("GOOS").Return(tc.GOOS)
|
env.On("GOOS").Return(tc.GOOS)
|
||||||
|
env.On("IsCygwin").Return(tc.Cygwin)
|
||||||
env.On("StackCount").Return(0)
|
env.On("StackCount").Return(0)
|
||||||
env.On("IsWsl").Return(false)
|
env.On("IsWsl").Return(false)
|
||||||
args := &runtime.Flags{
|
args := &runtime.Flags{
|
||||||
|
@ -780,7 +783,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
|
|
||||||
env.On("DebugF", testify_.Anything, testify_.Anything).Return(nil)
|
env.On("DebugF", testify_.Anything, testify_.Anything).Return(nil)
|
||||||
|
|
||||||
displayCygpath := tc.GOOS == runtime.WINDOWS && tc.Shell == shell.BASH
|
displayCygpath := tc.Cygwin
|
||||||
if displayCygpath {
|
if displayCygpath {
|
||||||
env.On("RunCommand", "cygpath", []string{"-u", tc.Pwd}).Return(tc.Cygpath, tc.CygpathError)
|
env.On("RunCommand", "cygpath", []string{"-u", tc.Pwd}).Return(tc.Cygpath, tc.CygpathError)
|
||||||
env.On("RunCommand", "cygpath", testify_.Anything).Return("brrrr", nil)
|
env.On("RunCommand", "cygpath", testify_.Anything).Return("brrrr", nil)
|
||||||
|
|
Loading…
Reference in a new issue