fix: escape \ from segment value when in bash

fix #738
This commit is contained in:
lnu 2021-05-25 14:45:21 +02:00 committed by Jan De Dobbeleer
parent 2cf288e46c
commit 2eb45b5863

View file

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"strings"
"sync" "sync"
"time" "time"
) )
@ -90,7 +91,13 @@ func (b *Block) renderSegments() string {
} }
b.activeSegment = segment b.activeSegment = segment
b.endPowerline() b.endPowerline()
b.renderSegmentText(segment.stringValue) segmentValue := segment.stringValue
// escape backslashes to avoid replacements
// https://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html
if b.env.getShellName() == bash {
segmentValue = strings.ReplaceAll(segment.stringValue, "\\", "\\\\")
}
b.renderSegmentText(segmentValue)
} }
if b.previousActiveSegment != nil && b.previousActiveSegment.Style == Powerline { if b.previousActiveSegment != nil && b.previousActiveSegment.Style == Powerline {
b.writePowerLineSeparator(Transparent, b.previousActiveSegment.background(), true) b.writePowerLineSeparator(Transparent, b.previousActiveSegment.background(), true)