2020-01-30 04:21:53 +00:00
|
|
|
# Updates the vscode setting file base on a nix expression
|
|
|
|
# should run from the workspace root.
|
|
|
|
{ writeShellScriptBin
|
|
|
|
, lib
|
|
|
|
, jq
|
|
|
|
}:
|
|
|
|
##User Input
|
|
|
|
{ settings ? {}
|
2021-09-09 18:45:33 +00:00
|
|
|
# if marked as true will create an empty json file if does not exist
|
2020-01-30 04:21:53 +00:00
|
|
|
, createIfDoesNotExists ? true
|
2020-02-02 21:25:57 +00:00
|
|
|
, vscodeSettingsFile ? ".vscode/settings.json"
|
2020-05-22 20:23:01 +00:00
|
|
|
, userSettingsFolder ? ""
|
|
|
|
, symlinkFromUserSetting ? false
|
2020-01-30 04:21:53 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
|
|
|
|
updateVSCodeSettingsCmd = ''
|
|
|
|
(
|
2020-08-30 23:17:48 +00:00
|
|
|
echo 'updateSettings.nix: Updating ${vscodeSettingsFile}...'
|
2020-02-02 21:25:57 +00:00
|
|
|
oldSettings=$(cat ${vscodeSettingsFile})
|
|
|
|
echo $oldSettings' ${builtins.toJSON settings}' | ${jq}/bin/jq -s add > ${vscodeSettingsFile}
|
2020-01-30 04:21:53 +00:00
|
|
|
)'';
|
|
|
|
|
2020-02-02 21:25:57 +00:00
|
|
|
createEmptySettingsCmd = ''mkdir -p .vscode && echo "{}" > ${vscodeSettingsFile}'';
|
2020-05-22 20:23:01 +00:00
|
|
|
fileName = builtins.baseNameOf vscodeSettingsFile;
|
|
|
|
symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting
|
|
|
|
'' && mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" '';
|
2020-08-30 23:17:48 +00:00
|
|
|
in
|
2020-02-02 21:25:57 +00:00
|
|
|
|
2020-05-22 20:23:01 +00:00
|
|
|
writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}''
|
2020-08-30 23:17:48 +00:00
|
|
|
(lib.optionalString (settings != {})
|
2020-05-22 20:23:01 +00:00
|
|
|
(if createIfDoesNotExists then ''
|
|
|
|
[ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd}
|
|
|
|
${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}
|
|
|
|
''
|
|
|
|
else ''[ -f "${vscodeSettingsFile}" ] && ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}
|
|
|
|
''
|
|
|
|
)
|
|
|
|
)
|