forked from VSCodium/vscodium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_settings.sh
executable file
·53 lines (45 loc) · 1.34 KB
/
update_settings.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
DEFAULT_TRUE="'default': true"
DEFAULT_FALSE="'default': false"
TELEMETRY_ENABLE="'telemetry.enableTelemetry':"
TELEMETRY_CRASH_REPORTER="'telemetry.enableCrashReporter':"
is_gnu_sed () {
sed --version >/dev/null 2>&1
}
replace () {
echo $1
if is_gnu_sed; then
sed -i -E "$1" $2
else
sed -i '' -E "$1" $2
fi
}
update_setting () {
local FILENAME="$2"
# check that the file exists
if [ ! -f $FILENAME ]; then
echo "File to update setting in does not exist ${FILENAME}"
return
fi
# go through lines of file, looking for block that contains setting
local SETTING="$1"
local LINE_NUM=0
while read -r line; do
local LINE_NUM=$(( $LINE_NUM + 1 ))
if [[ $line == *"$SETTING"* ]]; then
local IN_SETTING=1
fi
if [[ $line == *"$DEFAULT_TRUE"* && "$IN_SETTING" == "1" ]]; then
local FOUND=1
break
fi
done < $FILENAME
if [[ "$FOUND" != "1" ]]; then
echo "$DEFAULT_TRUE not found for setting $SETTING in file $FILENAME"
return
fi
# construct line-aware replacement string
local DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_TRUE}/${DEFAULT_FALSE}/"
replace "$DEFAULT_TRUE_TO_FALSE" $FILENAME
}
update_setting "$TELEMETRY_ENABLE" src/vs/platform/telemetry/common/telemetryService.ts
update_setting "$TELEMETRY_CRASH_REPORTER" src/vs/workbench/electron-sandbox/desktop.contribution.ts