mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
fix(shell): escape special characters correctly
This commit is contained in:
parent
dfae989782
commit
c0935c87f2
|
@ -266,9 +266,12 @@ func (a *Ansi) ClearAfter() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Ansi) Title(title string) string {
|
func (a *Ansi) Title(title string) string {
|
||||||
// we have to do this to prevent bash from misidentifying escape sequences
|
// we have to do this to prevent bash/zsh from misidentifying escape sequences
|
||||||
if a.shell == shell.BASH {
|
switch a.shell {
|
||||||
title = strings.ReplaceAll(title, `\`, `\\`)
|
case shell.BASH:
|
||||||
|
title = strings.NewReplacer("`", "\\`", `\`, `\\`).Replace(title)
|
||||||
|
case shell.ZSH:
|
||||||
|
title = strings.NewReplacer("`", "\\`", `%`, `%%`).Replace(title)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(a.title, title)
|
return fmt.Sprintf(a.title, title)
|
||||||
}
|
}
|
||||||
|
|
|
@ -395,12 +395,11 @@ func (segment *Segment) SetText() {
|
||||||
if segment.Interactive {
|
if segment.Interactive {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// we have to do this to prevent bash/zsh from misidentifying escape sequences
|
||||||
switch segment.env.Shell() {
|
switch segment.env.Shell() {
|
||||||
case shell.BASH, shell.FISH:
|
case shell.BASH:
|
||||||
segment.text = strings.ReplaceAll(segment.text, `\`, `\\`)
|
segment.text = strings.NewReplacer("`", "\\`", `\`, `\\`).Replace(segment.text)
|
||||||
case shell.ZSH:
|
case shell.ZSH:
|
||||||
segment.text = strings.ReplaceAll(segment.text, `%`, `%%`)
|
segment.text = strings.NewReplacer("`", "\\`", `%`, `%%`).Replace(segment.text)
|
||||||
case shell.PWSH, shell.PWSH5:
|
|
||||||
segment.text = strings.ReplaceAll(segment.text, "`", "``")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue