mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -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 {
|
||||
// we have to do this to prevent bash from misidentifying escape sequences
|
||||
if a.shell == shell.BASH {
|
||||
title = strings.ReplaceAll(title, `\`, `\\`)
|
||||
// we have to do this to prevent bash/zsh from misidentifying escape sequences
|
||||
switch a.shell {
|
||||
case shell.BASH:
|
||||
title = strings.NewReplacer("`", "\\`", `\`, `\\`).Replace(title)
|
||||
case shell.ZSH:
|
||||
title = strings.NewReplacer("`", "\\`", `%`, `%%`).Replace(title)
|
||||
}
|
||||
return fmt.Sprintf(a.title, title)
|
||||
}
|
||||
|
|
|
@ -395,12 +395,11 @@ func (segment *Segment) SetText() {
|
|||
if segment.Interactive {
|
||||
return
|
||||
}
|
||||
// we have to do this to prevent bash/zsh from misidentifying escape sequences
|
||||
switch segment.env.Shell() {
|
||||
case shell.BASH, shell.FISH:
|
||||
segment.text = strings.ReplaceAll(segment.text, `\`, `\\`)
|
||||
case shell.BASH:
|
||||
segment.text = strings.NewReplacer("`", "\\`", `\`, `\\`).Replace(segment.text)
|
||||
case shell.ZSH:
|
||||
segment.text = strings.ReplaceAll(segment.text, `%`, `%%`)
|
||||
case shell.PWSH, shell.PWSH5:
|
||||
segment.text = strings.ReplaceAll(segment.text, "`", "``")
|
||||
segment.text = strings.NewReplacer("`", "\\`", `%`, `%%`).Replace(segment.text)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue