-
Notifications
You must be signed in to change notification settings - Fork 0
/
vscodium.ts
91 lines (81 loc) · 2.35 KB
/
vscodium.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { writeTextFile } from "https://garn.io/ts/v0.0.18/internal/utils.ts";
import * as garn from "https://garn.io/ts/v0.0.18/mod.ts";
import { nix } from "https://garn.io/ts/v0.0.18/mod.ts";
import { NixExpression } from "https://garn.io/ts/v0.0.18/nix.ts";
import { knockOut } from "./knockout.ts";
import { exampleFile } from "./exampleFile.ts";
const vscodium: nix.NixExpression = nix.nixRaw`
(pkgs.vscode-with-extensions.override
{
vscode = pkgs.vscodium;
vscodeExtensions = [
];
}
)
`;
/**
* Create a fake home directory that contains the given config.
*/
const tempHomeDir = (settings: Record<string, unknown>): garn.Package => {
return garn.build`
USER_CONFIG=.config/VSCodium/User
if test $(uname) = "Darwin" ; then
USER_CONFIG="Library/Application Support/VSCodium/User"
fi
mkdir -p "$out/$USER_CONFIG/User"
cp ${writeTextFile(
"vscodium-config",
JSON.stringify(settings, null, 2),
)} "$out/$USER_CONFIG/settings.json"
`;
};
const openVsCodium = (
args: {
settings?: Record<string, unknown>;
file?: NixExpression;
} = {},
): garn.Executable => {
const file = args.file ? args.file : "";
return garn.shell`
set -euo pipefail
TEMP_DIR=$(mktemp -d --suffix vscodium)
# copy the vscodium config
cp -r ${tempHomeDir(args.settings ?? {})}/. $TEMP_DIR
chmod -R u+rwX $TEMP_DIR
export HOME=$TEMP_DIR
export XDG_CONFIG_HOME=$TEMP_DIR/.config
killVsCodium() {
kill $(cat $XDG_CONFIG_HOME/VSCodium/code.lock) || true;
rm -rf $TEMP_DIR
}
trap "killVsCodium &> /dev/null" EXIT
${vscodium}/bin/codium --new-window --disable-workspace-trust ${file} --wait
`.setDescription("open vscodium");
};
export const vscodiumColorschemes = [
"Abyss",
"Default Dark+",
"Default High Contrast",
"Default High Contrast Light",
"Default Light+",
"Default Light Modern",
"Kimbie Dark",
"Monokai",
"Monokai Dimmed",
"Quiet Light",
"Red",
"Solarized Dark",
"Solarized Light",
"Tomorrow Night Blue",
"Visual Studio Dark",
"Visual Studio Light",
];
export const vscodiumWithColorscheme = (colorscheme: string): garn.Executable =>
openVsCodium({
file: nix.nixStrLit`${exampleFile}`,
settings: {
"update.mode": "none",
"window.menuBarVisibility": "hidden",
"workbench.colorTheme": colorscheme,
},
});