47
47
48
48
# Apply EnvironmentVariableCollections if needed
49
49
if [ -n " ${VSCODE_ENV_REPLACE:- } " ]; then
50
- IFS=' :' read -ra ADDR <<< " $VSCODE_ENV_REPLACE"
50
+ IFS=' :' read -ra ADDR <<< " $VSCODE_ENV_REPLACE"
51
51
for ITEM in " ${ADDR[@]} " ; do
52
52
VARNAME=" $( echo $ITEM | cut -d " =" -f 1) "
53
53
VALUE=" $( echo -e " $ITEM " | cut -d " =" -f 2) "
@@ -56,7 +56,7 @@ if [ -n "${VSCODE_ENV_REPLACE:-}" ]; then
56
56
builtin unset VSCODE_ENV_REPLACE
57
57
fi
58
58
if [ -n " ${VSCODE_ENV_PREPEND:- } " ]; then
59
- IFS=' :' read -ra ADDR <<< " $VSCODE_ENV_PREPEND"
59
+ IFS=' :' read -ra ADDR <<< " $VSCODE_ENV_PREPEND"
60
60
for ITEM in " ${ADDR[@]} " ; do
61
61
VARNAME=" $( echo $ITEM | cut -d " =" -f 1) "
62
62
VALUE=" $( echo -e " $ITEM " | cut -d " =" -f 2) "
@@ -65,7 +65,7 @@ if [ -n "${VSCODE_ENV_PREPEND:-}" ]; then
65
65
builtin unset VSCODE_ENV_PREPEND
66
66
fi
67
67
if [ -n " ${VSCODE_ENV_APPEND:- } " ]; then
68
- IFS=' :' read -ra ADDR <<< " $VSCODE_ENV_APPEND"
68
+ IFS=' :' read -ra ADDR <<< " $VSCODE_ENV_APPEND"
69
69
for ITEM in " ${ADDR[@]} " ; do
70
70
VARNAME=" $( echo $ITEM | cut -d " =" -f 1) "
71
71
VALUE=" $( echo -e " $ITEM " | cut -d " =" -f 2) "
@@ -95,52 +95,13 @@ __vsc_get_trap() {
95
95
builtin printf ' %s' " ${terms[2]:- } "
96
96
}
97
97
98
- __vsc_command_available () {
99
- builtin local trash
100
- trash=$( builtin command -v " $1 " 2>&1 )
101
- builtin return $?
102
- }
103
-
104
- # We provide two faster escaping functions here.
105
- # The first one escapes each byte 0xab into '\xab', which is most scalable and has promising runtime
106
- # efficiency, except that it relies on external commands od and tr.
107
- # The second one is much faster and has zero dependency, except that it escapes only
108
- # '\\' -> '\\\\' and ';' -> '\x3b' and scales up badly when more patterns are needed.
109
- # We default to use the first function if od and tr are available, and fallback to the second otherwise.
110
- if __vsc_command_available od && __vsc_command_available tr; then
111
- __vsc_escape_value_fast () {
112
- builtin local out
113
- # -An removes line number
114
- # -v do not use * to mark line suppression
115
- # -tx1 prints each byte as two-digit hex
116
- # tr -d '\n' concats all output lines
117
- out=$( od -An -vtx1 <<< " $1" | tr -d ' \n' )
118
- out=${out// / \\ x}
119
- # <<<"$1" prepends a trailing newline already, so we don't need to printf '%s\n'
120
- builtin printf ' %s' " ${out} "
121
- }
122
- else
123
- __vsc_escape_value_fast () {
124
- builtin local LC_ALL=C out
125
- out=${1// \\ / \\\\ }
126
- out=${out// ;/ \\ x3b}
127
- builtin printf ' %s\n' " ${out} "
128
- }
129
- fi
130
-
131
98
# The property (P) and command (E) codes embed values which require escaping.
132
99
# Backslashes are doubled. Non-alphanumeric characters are converted to escaped hex.
133
100
__vsc_escape_value () {
134
- # If the input being too large, switch to the faster function
135
- if [ " ${# 1} " -ge 2000 ]; then
136
- __vsc_escape_value_fast " $1 "
137
- builtin return
138
- fi
139
-
140
101
# Process text byte by byte, not by codepoint.
141
102
builtin local LC_ALL=C str=" ${1} " i byte token out=' '
142
103
143
- for (( i = 0 ; i < "${# str} "; ++ i)) ; do
104
+ for (( i = 0 ; i < "${# str} "; ++ i )) ; do
144
105
byte=" ${str: $i : 1} "
145
106
146
107
# Escape backslashes and semi-colons
0 commit comments