mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
fix(windows): only reformat pwd on cygwin
This commit is contained in:
parent
1a7f2d2d10
commit
51c3f9e0eb
|
@ -69,21 +69,25 @@ func (e *Engine) canWriteRightBlock(length int, rprompt bool) (int, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) pwd() {
|
func (e *Engine) pwd() {
|
||||||
// only print when supported
|
|
||||||
sh := e.Env.Shell()
|
|
||||||
if sh == shell.ELVISH || sh == shell.XONSH {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// only print when relevant
|
// only print when relevant
|
||||||
if len(e.Config.PWD) == 0 && !e.Config.OSC99 {
|
if len(e.Config.PWD) == 0 && !e.Config.OSC99 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cwd := e.Env.Pwd()
|
// only print when supported
|
||||||
|
sh := e.Env.Shell()
|
||||||
|
if sh == shell.ELVISH || sh == shell.XONSH {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pwd := e.Env.Pwd()
|
||||||
|
if e.Env.IsCygwin() {
|
||||||
|
pwd = strings.ReplaceAll(pwd, `\`, `/`)
|
||||||
|
}
|
||||||
|
|
||||||
// Backwards compatibility for deprecated OSC99
|
// Backwards compatibility for deprecated OSC99
|
||||||
if e.Config.OSC99 {
|
if e.Config.OSC99 {
|
||||||
e.write(terminal.Pwd(terminal.OSC99, "", "", cwd))
|
e.write(terminal.Pwd(terminal.OSC99, "", "", pwd))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +104,7 @@ func (e *Engine) pwd() {
|
||||||
|
|
||||||
user := e.Env.User()
|
user := e.Env.User()
|
||||||
host, _ := e.Env.Host()
|
host, _ := e.Env.Host()
|
||||||
e.write(terminal.Pwd(pwdType, user, host, cwd))
|
e.write(terminal.Pwd(pwdType, user, host, pwd))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) getNewline() string {
|
func (e *Engine) getNewline() string {
|
||||||
|
|
|
@ -55,22 +55,30 @@ func TestPrintPWD(t *testing.T) {
|
||||||
Config string
|
Config string
|
||||||
Pwd string
|
Pwd string
|
||||||
Shell string
|
Shell string
|
||||||
|
Cygwin bool
|
||||||
OSC99 bool
|
OSC99 bool
|
||||||
}{
|
}{
|
||||||
{Case: "Empty PWD"},
|
{Case: "Empty PWD"},
|
||||||
{Case: "OSC99", Config: terminal.OSC99, Expected: "\x1b]9;9;pwd\x1b\\"},
|
{Case: "OSC99", Config: terminal.OSC99, Expected: "\x1b]9;9;pwd\x1b\\"},
|
||||||
|
{Case: "OSC99 - Elvish", Config: terminal.OSC99, Shell: shell.ELVISH},
|
||||||
{Case: "OSC7", Config: terminal.OSC7, Expected: "\x1b]7;file://host/pwd\x1b\\"},
|
{Case: "OSC7", Config: terminal.OSC7, Expected: "\x1b]7;file://host/pwd\x1b\\"},
|
||||||
{Case: "OSC51", Config: terminal.OSC51, Expected: "\x1b]51;Auser@host:pwd\x1b\\"},
|
{Case: "OSC51", Config: terminal.OSC51, Expected: "\x1b]51;Auser@host:pwd\x1b\\"},
|
||||||
{Case: "Deprecated OSC99", OSC99: true, Expected: "\x1b]9;9;pwd\x1b\\"},
|
{Case: "Deprecated OSC99", OSC99: true, Expected: "\x1b]9;9;pwd\x1b\\"},
|
||||||
{Case: "Template (empty)", Config: "{{ if eq .Shell \"pwsh\" }}osc7{{ end }}"},
|
{Case: "Template (empty)", Config: "{{ if eq .Shell \"pwsh\" }}osc7{{ end }}"},
|
||||||
{Case: "Template (non empty)", Config: "{{ if eq .Shell \"shell\" }}osc7{{ end }}", Expected: "\x1b]7;file://host/pwd\x1b\\"},
|
{Case: "Template (non empty)", Config: "{{ if eq .Shell \"shell\" }}osc7{{ end }}", Expected: "\x1b]7;file://host/pwd\x1b\\"},
|
||||||
{
|
{
|
||||||
Case: "OSC99 Bash",
|
Case: "OSC99 Cygwin",
|
||||||
Pwd: `C:\Users\user\Documents\GitHub\oh-my-posh`,
|
Pwd: `C:\Users\user\Documents\GitHub\oh-my-posh`,
|
||||||
Config: terminal.OSC99,
|
Config: terminal.OSC99,
|
||||||
Shell: shell.BASH,
|
Cygwin: true,
|
||||||
Expected: "\x1b]9;9;C:/Users/user/Documents/GitHub/oh-my-posh\x1b\\",
|
Expected: "\x1b]9;9;C:/Users/user/Documents/GitHub/oh-my-posh\x1b\\",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Case: "OSC99 Windows",
|
||||||
|
Pwd: `C:\Users\user\Documents\GitHub\oh-my-posh`,
|
||||||
|
Config: terminal.OSC99,
|
||||||
|
Expected: "\x1b]9;9;C:\\Users\\user\\Documents\\GitHub\\oh-my-posh\x1b\\",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
@ -78,9 +86,11 @@ func TestPrintPWD(t *testing.T) {
|
||||||
if len(tc.Pwd) == 0 {
|
if len(tc.Pwd) == 0 {
|
||||||
tc.Pwd = "pwd"
|
tc.Pwd = "pwd"
|
||||||
}
|
}
|
||||||
|
|
||||||
env.On("Pwd").Return(tc.Pwd)
|
env.On("Pwd").Return(tc.Pwd)
|
||||||
env.On("Shell").Return(tc.Shell)
|
|
||||||
env.On("User").Return("user")
|
env.On("User").Return("user")
|
||||||
|
env.On("Shell").Return(tc.Shell)
|
||||||
|
env.On("IsCygwin").Return(tc.Cygwin)
|
||||||
env.On("Host").Return("host", nil)
|
env.On("Host").Return("host", nil)
|
||||||
env.On("DebugF", testify_.Anything, testify_.Anything).Return(nil)
|
env.On("DebugF", testify_.Anything, testify_.Anything).Return(nil)
|
||||||
env.On("TemplateCache").Return(&cache.Template{
|
env.On("TemplateCache").Return(&cache.Template{
|
||||||
|
|
|
@ -3,6 +3,7 @@ export POSH_SHELL_VERSION=$BASH_VERSION
|
||||||
export POWERLINE_COMMAND="oh-my-posh"
|
export POWERLINE_COMMAND="oh-my-posh"
|
||||||
export POSH_PID=$$
|
export POSH_PID=$$
|
||||||
export CONDA_PROMPT_MODIFIER=false
|
export CONDA_PROMPT_MODIFIER=false
|
||||||
|
export OSTYPE=$OSTYPE
|
||||||
|
|
||||||
# global variables
|
# global variables
|
||||||
_omp_start_time=""
|
_omp_start_time=""
|
||||||
|
|
|
@ -166,8 +166,6 @@ func Pwd(pwdType, userName, hostName, pwd string) string {
|
||||||
pwd += `/`
|
pwd += `/`
|
||||||
}
|
}
|
||||||
|
|
||||||
pwd = strings.ReplaceAll(pwd, `\`, `/`)
|
|
||||||
|
|
||||||
switch pwdType {
|
switch pwdType {
|
||||||
case OSC7:
|
case OSC7:
|
||||||
return fmt.Sprintf(formats.Osc7, hostName, pwd)
|
return fmt.Sprintf(formats.Osc7, hostName, pwd)
|
||||||
|
|
Loading…
Reference in a new issue