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 19:45:33 +01: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 21:23:01 +01:00
|
|
|
, userSettingsFolder ? ""
|
|
|
|
, symlinkFromUserSetting ? false
|
2020-01-30 04:21:53 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
|
|
|
|
updateVSCodeSettingsCmd = ''
|
|
|
|
(
|
2020-08-31 00:17:48 +01: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 21:23:01 +01:00
|
|
|
fileName = builtins.baseNameOf vscodeSettingsFile;
|
|
|
|
symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting
|
|
|
|
'' && mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" '';
|
2020-08-31 00:17:48 +01:00
|
|
|
in
|
2020-02-02 21:25:57 +00:00
|
|
|
|
2020-05-22 21:23:01 +01:00
|
|
|
writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}''
|
2020-08-31 00:17:48 +01:00
|
|
|
(lib.optionalString (settings != {})
|
2020-05-22 21:23:01 +01:00
|
|
|
(if createIfDoesNotExists then ''
|
|
|
|
[ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd}
|
|
|
|
${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}
|
|
|
|
''
|
|
|
|
else ''[ -f "${vscodeSettingsFile}" ] && ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}
|
|
|
|
''
|
|
|
|
)
|
|
|
|
)
|