vscodium/update_settings.sh

56 lines
1.8 KiB
Bash
Raw Normal View History

# shellcheck disable=SC1091,2148
DEFAULT_TRUE="'default': true"
DEFAULT_FALSE="'default': false"
DEFAULT_ON="'default': TelemetryConfiguration.ON"
DEFAULT_OFF="'default': TelemetryConfiguration.OFF"
TELEMETRY_CRASH_REPORTER="'telemetry.enableCrashReporter':"
TELEMETRY_CONFIGURATION=" TelemetryConfiguration.ON"
NLS=workbench.settings.enableNaturalLanguageSearch
2022-08-16 14:51:45 +03:00
# include common functions
. ../utils.sh
update_setting () {
2023-07-23 19:35:27 +03:00
local FILENAME SETTING LINE_NUM IN_SETTING FOUND DEFAULT_TRUE_TO_FALSE
FILENAME="${2}"
# check that the file exists
2023-07-23 19:35:27 +03:00
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
2023-07-23 19:35:27 +03:00
SETTING="${1}"
LINE_NUM=0
while read -r line; do
2023-07-23 19:35:27 +03:00
LINE_NUM=$(( LINE_NUM + 1 ))
if [[ "${line}" == *"${SETTING}"* ]]; then
2023-07-23 19:35:27 +03:00
IN_SETTING=1
fi
if [[ ("${line}" == *"${DEFAULT_TRUE}"* || "${line}" == *"${DEFAULT_ON}"*) && "${IN_SETTING}" == "1" ]]; then
2023-07-23 19:35:27 +03:00
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
if [[ "${line}" == *"${DEFAULT_TRUE}"* ]]; then
2023-07-23 19:35:27 +03:00
DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_TRUE}/${DEFAULT_FALSE}/"
else
2023-07-23 19:35:27 +03:00
DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_ON}/${DEFAULT_OFF}/"
fi
replace "${DEFAULT_TRUE_TO_FALSE}" "${FILENAME}"
}
update_setting "${TELEMETRY_CRASH_REPORTER}" src/vs/workbench/electron-sandbox/desktop.contribution.ts
update_setting "${TELEMETRY_CONFIGURATION}" src/vs/platform/telemetry/common/telemetryService.ts
update_setting "${NLS}" src/vs/workbench/contrib/preferences/common/preferencesContribution.ts