update_settings.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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="${2}"
  13. # check that the file exists
  14. if [ ! -f "${FILENAME}" ]; then
  15. echo "File to update setting in does not exist ${FILENAME}"
  16. return
  17. fi
  18. # go through lines of file, looking for block that contains setting
  19. local SETTING="${1}"
  20. local LINE_NUM=0
  21. while read -r line; do
  22. local LINE_NUM=$(( LINE_NUM + 1 ))
  23. if [[ "${line}" == *"${SETTING}"* ]]; then
  24. local IN_SETTING=1
  25. fi
  26. if [[ ("${line}" == *"${DEFAULT_TRUE}"* || "${line}" == *"${DEFAULT_ON}"*) && "${IN_SETTING}" == "1" ]]; then
  27. local FOUND=1
  28. break
  29. fi
  30. done < "${FILENAME}"
  31. if [[ "${FOUND}" != "1" ]]; then
  32. echo "${DEFAULT_TRUE} not found for setting ${SETTING} in file ${FILENAME}"
  33. return
  34. fi
  35. # construct line-aware replacement string
  36. if [[ "${line}" == *"${DEFAULT_TRUE}"* ]]; then
  37. local DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_TRUE}/${DEFAULT_FALSE}/"
  38. else
  39. local DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_ON}/${DEFAULT_OFF}/"
  40. fi
  41. replace "${DEFAULT_TRUE_TO_FALSE}" "${FILENAME}"
  42. }
  43. update_setting "${TELEMETRY_CRASH_REPORTER}" src/vs/workbench/electron-sandbox/desktop.contribution.ts
  44. update_setting "${TELEMETRY_CONFIGURATION}" src/vs/platform/telemetry/common/telemetryService.ts
  45. update_setting "${NLS}" src/vs/workbench/contrib/preferences/common/preferencesContribution.ts