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