mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
2c7aa8c490
commit
a9e2ba61fa
|
@ -91,6 +91,12 @@ func (e *Engine) pwd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
cwd := e.Env.Pwd()
|
cwd := e.Env.Pwd()
|
||||||
|
|
||||||
|
// in BASH, we need to escape the path
|
||||||
|
if e.Env.Shell() == shell.BASH {
|
||||||
|
cwd = strings.ReplaceAll(cwd, `\`, `\\`)
|
||||||
|
}
|
||||||
|
|
||||||
// Backwards compatibility for deprecated OSC99
|
// Backwards compatibility for deprecated OSC99
|
||||||
if e.Config.OSC99 {
|
if e.Config.OSC99 {
|
||||||
e.write(e.Writer.ConsolePwd(ansi.OSC99, "", "", cwd))
|
e.write(e.Writer.ConsolePwd(ansi.OSC99, "", "", cwd))
|
||||||
|
|
|
@ -49,22 +49,34 @@ func TestPrintPWD(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
Expected string
|
Expected string
|
||||||
PWD string
|
Config string
|
||||||
|
Pwd string
|
||||||
|
Shell string
|
||||||
OSC99 bool
|
OSC99 bool
|
||||||
}{
|
}{
|
||||||
{Case: "Empty PWD"},
|
{Case: "Empty PWD"},
|
||||||
{Case: "OSC99", PWD: ansi.OSC99, Expected: "\x1b]9;9;pwd\x1b\\"},
|
{Case: "OSC99", Config: ansi.OSC99, Expected: "\x1b]9;9;pwd\x1b\\"},
|
||||||
{Case: "OSC7", PWD: ansi.OSC7, Expected: "\x1b]7;file://host/pwd\x1b\\"},
|
{Case: "OSC7", Config: ansi.OSC7, Expected: "\x1b]7;file://host/pwd\x1b\\"},
|
||||||
{Case: "OSC51", PWD: ansi.OSC51, Expected: "\x1b]51;Auser@host:pwd\x1b\\"},
|
{Case: "OSC51", Config: ansi.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)", PWD: "{{ if eq .Shell \"pwsh\" }}osc7{{ end }}"},
|
{Case: "Template (empty)", Config: "{{ if eq .Shell \"pwsh\" }}osc7{{ end }}"},
|
||||||
{Case: "Template (non empty)", PWD: "{{ 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",
|
||||||
|
Pwd: `C:\Users\user\Documents\GitHub\oh-my-posh`,
|
||||||
|
Config: ansi.OSC99,
|
||||||
|
Shell: shell.BASH,
|
||||||
|
Expected: "\x1b]9;9;C:\\\\Users\\\\user\\\\Documents\\\\GitHub\\\\oh-my-posh\x1b\\",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := new(mock.MockedEnvironment)
|
env := new(mock.MockedEnvironment)
|
||||||
env.On("Pwd").Return("pwd")
|
if len(tc.Pwd) == 0 {
|
||||||
env.On("Shell").Return("shell")
|
tc.Pwd = "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("Host").Return("host", nil)
|
env.On("Host").Return("host", nil)
|
||||||
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
|
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
|
||||||
|
@ -78,7 +90,7 @@ func TestPrintPWD(t *testing.T) {
|
||||||
engine := &Engine{
|
engine := &Engine{
|
||||||
Env: env,
|
Env: env,
|
||||||
Config: &Config{
|
Config: &Config{
|
||||||
PWD: tc.PWD,
|
PWD: tc.Config,
|
||||||
OSC99: tc.OSC99,
|
OSC99: tc.OSC99,
|
||||||
},
|
},
|
||||||
Writer: writer,
|
Writer: writer,
|
||||||
|
|
Loading…
Reference in a new issue