update_settings.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # shellcheck disable=SC1091,2148
  2. DEFAULT_TRUE="'default': true"
  3. DEFAULT_FALSE="'default': false"
  4. DEFAULT_ON="'default': TelemetryConfiguration.ON"
  5. DEFAULT_OFF="'default': TelemetryConfiguration.OFF"
  6. TELEMETRY_CRASH_REPORTER="'telemetry.enableCrashReporter':"
  7. TELEMETRY_CONFIGURATION=" TelemetryConfiguration.ON"
  8. NLS=workbench.settings.enableNaturalLanguageSearch
  9. # include common functions
  10. . ../utils.sh
  11. update_setting () {
  12. local FILENAME SETTING LINE_NUM IN_SETTING FOUND DEFAULT_TRUE_TO_FALSE
  13. FILENAME="${2}"
  14. # check that the file exists
  15. if [[ ! -f "${FILENAME}" ]]; then
  16. echo "File to update setting in does not exist ${FILENAME}"
  17. return
  18. fi
  19. # go through lines of file, looking for block that contains setting
  20. SETTING="${1}"
  21. LINE_NUM=0
  22. while read -r line; do
  23. LINE_NUM=$(( LINE_NUM + 1 ))
  24. if [[ "${line}" == *"${SETTING}"* ]]; then
  25. IN_SETTING=1
  26. fi
  27. if [[ ("${line}" == *"${DEFAULT_TRUE}"* || "${line}" == *"${DEFAULT_ON}"*) && "${IN_SETTING}" == "1" ]]; then
  28. FOUND=1
  29. break
  30. fi
  31. done < "${FILENAME}"
  32. if [[ "${FOUND}" != "1" ]]; then
  33. echo "${DEFAULT_TRUE} not found for setting ${SETTING} in file ${FILENAME}"
  34. return
  35. fi
  36. # construct line-aware replacement string
  37. if [[ "${line}" == *"${DEFAULT_TRUE}"* ]]; then
  38. DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_TRUE}/${DEFAULT_FALSE}/"
  39. else
  40. DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_ON}/${DEFAULT_OFF}/"
  41. fi
  42. replace "${DEFAULT_TRUE_TO_FALSE}" "${FILENAME}"
  43. }
  44. update_setting "${TELEMETRY_CRASH_REPORTER}" src/vs/workbench/electron-sandbox/desktop.contribution.ts
  45. update_setting "${TELEMETRY_CONFIGURATION}" src/vs/platform/telemetry/common/telemetryService.ts
  46. update_setting "${NLS}" src/vs/workbench/contrib/preferences/common/preferencesContribution.ts