Skip to content

Commit 2bf5bb3

Browse files
authored
Merge pull request #214608 from microsoft/tyriar/r1_90_214606
Use faster printf method in bash SI script
2 parents a7a94fb + 5bbd161 commit 2bf5bb3

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,34 @@ __vsc_escape_value() {
112112
fi
113113

114114
# Process text byte by byte, not by codepoint.
115-
builtin local LC_ALL=C str="${1}" i byte token out=''
115+
local -r LC_ALL=C
116+
local -r str="${1}"
117+
local -ir len="${#str}"
118+
119+
local -i i
120+
local -i val
121+
local byte
122+
local token
123+
local out=''
116124

117125
for (( i=0; i < "${#str}"; ++i )); do
126+
# Escape backslashes, semi-colons specially, then special ASCII chars below space (0x20).
118127
byte="${str:$i:1}"
119-
120-
# Escape backslashes, semi-colons specially, then special ASCII chars below space (0x20)
121-
if [ "$byte" = "\\" ]; then
128+
builtin printf -v val '%d' "'$byte"
129+
if (( val < 31 )); then
130+
builtin printf -v token '\\x%02x' "'$byte"
131+
elif (( val == 92 )); then # \
122132
token="\\\\"
123-
elif [ "$byte" = ";" ]; then
133+
elif (( val == 59 )); then # ;
124134
token="\\x3b"
125-
elif (( $(builtin printf '%d' "'$byte") < 31 )); then
126-
token=$(builtin printf '\\x%02x' "'$byte")
127135
else
128136
token="$byte"
129137
fi
130138

131139
out+="$token"
132140
done
133141

134-
builtin printf '%s\n' "${out}"
142+
builtin printf '%s\n' "$out"
135143
}
136144

137145
# Send the IsWindows property if the environment looks like Windows

0 commit comments

Comments
 (0)