Skip to content

Commit 7bdff6c

Browse files
fix: To support a single cross-platform settings file some of the settings sh
Fixes #2584
1 parent da0c401 commit 7bdff6c

4 files changed

Lines changed: 266 additions & 0 deletions

File tree

app/config/schema.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,27 @@
168168
"description": "for environment variables",
169169
"type": "object"
170170
},
171+
"envLinux": {
172+
"additionalProperties": {
173+
"type": "string"
174+
},
175+
"description": "platform-specific env override for Linux (merged with `env` on Linux)",
176+
"type": "object"
177+
},
178+
"envOsx": {
179+
"additionalProperties": {
180+
"type": "string"
181+
},
182+
"description": "platform-specific env override for macOS (merged with `env` on macOS)",
183+
"type": "object"
184+
},
185+
"envWindows": {
186+
"additionalProperties": {
187+
"type": "string"
188+
},
189+
"description": "platform-specific env override for Windows (merged with `env` on Windows)",
190+
"type": "object"
191+
},
171192
"fontFamily": {
172193
"description": "font family with optional fallbacks",
173194
"type": "string"
@@ -253,6 +274,39 @@
253274
},
254275
"type": "array"
255276
},
277+
"shellArgsLinux": {
278+
"description": "platform-specific shellArgs override for Linux (overrides `shellArgs` on Linux)",
279+
"items": {
280+
"type": "string"
281+
},
282+
"type": "array"
283+
},
284+
"shellArgsOsx": {
285+
"description": "platform-specific shellArgs override for macOS (overrides `shellArgs` on macOS)",
286+
"items": {
287+
"type": "string"
288+
},
289+
"type": "array"
290+
},
291+
"shellArgsWindows": {
292+
"description": "platform-specific shellArgs override for Windows (overrides `shellArgs` on Windows)",
293+
"items": {
294+
"type": "string"
295+
},
296+
"type": "array"
297+
},
298+
"shellLinux": {
299+
"description": "platform-specific shell override for Linux (overrides `shell` on Linux)",
300+
"type": "string"
301+
},
302+
"shellOsx": {
303+
"description": "platform-specific shell override for macOS (overrides `shell` on macOS)",
304+
"type": "string"
305+
},
306+
"shellWindows": {
307+
"description": "platform-specific shell override for Windows (overrides `shell` on Windows)",
308+
"type": "string"
309+
},
256310
"showHamburgerMenu": {
257311
"description": "if you're using a Linux setup which show native menus, set to false\n\ndefault: `true` on Linux, `true` on Windows, ignored on macOS",
258312
"enum": [
@@ -495,6 +549,27 @@
495549
"description": "for environment variables",
496550
"type": "object"
497551
},
552+
"envLinux": {
553+
"additionalProperties": {
554+
"type": "string"
555+
},
556+
"description": "platform-specific env override for Linux (merged with `env` on Linux)",
557+
"type": "object"
558+
},
559+
"envOsx": {
560+
"additionalProperties": {
561+
"type": "string"
562+
},
563+
"description": "platform-specific env override for macOS (merged with `env` on macOS)",
564+
"type": "object"
565+
},
566+
"envWindows": {
567+
"additionalProperties": {
568+
"type": "string"
569+
},
570+
"description": "platform-specific env override for Windows (merged with `env` on Windows)",
571+
"type": "object"
572+
},
498573
"fontFamily": {
499574
"description": "font family with optional fallbacks",
500575
"type": "string"
@@ -580,6 +655,39 @@
580655
},
581656
"type": "array"
582657
},
658+
"shellArgsLinux": {
659+
"description": "platform-specific shellArgs override for Linux (overrides `shellArgs` on Linux)",
660+
"items": {
661+
"type": "string"
662+
},
663+
"type": "array"
664+
},
665+
"shellArgsOsx": {
666+
"description": "platform-specific shellArgs override for macOS (overrides `shellArgs` on macOS)",
667+
"items": {
668+
"type": "string"
669+
},
670+
"type": "array"
671+
},
672+
"shellArgsWindows": {
673+
"description": "platform-specific shellArgs override for Windows (overrides `shellArgs` on Windows)",
674+
"items": {
675+
"type": "string"
676+
},
677+
"type": "array"
678+
},
679+
"shellLinux": {
680+
"description": "platform-specific shell override for Linux (overrides `shell` on Linux)",
681+
"type": "string"
682+
},
683+
"shellOsx": {
684+
"description": "platform-specific shell override for macOS (overrides `shell` on macOS)",
685+
"type": "string"
686+
},
687+
"shellWindows": {
688+
"description": "platform-specific shell override for Windows (overrides `shell` on Windows)",
689+
"type": "string"
690+
},
583691
"showHamburgerMenu": {
584692
"description": "if you're using a Linux setup which show native menus, set to false\n\ndefault: `true` on Linux, `true` on Windows, ignored on macOS",
585693
"enum": [
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type {configOptions} from '../../typings/config';
2+
3+
type PlatformSuffix = 'Osx' | 'Windows' | 'Linux';
4+
5+
const PLATFORM_SUFFIX_MAP: Partial<Record<NodeJS.Platform, PlatformSuffix>> = {
6+
darwin: 'Osx',
7+
win32: 'Windows',
8+
linux: 'Linux'
9+
};
10+
11+
export const resolvePlatformConfig = (
12+
config: configOptions,
13+
platform: NodeJS.Platform = process.platform
14+
): configOptions => {
15+
const suffix = PLATFORM_SUFFIX_MAP[platform];
16+
if (!suffix) return config;
17+
18+
const result = {...config};
19+
const shellKey = `shell${suffix}` as `shell${PlatformSuffix}`;
20+
const shellArgsKey = `shellArgs${suffix}` as `shellArgs${PlatformSuffix}`;
21+
const envKey = `env${suffix}` as `env${PlatformSuffix}`;
22+
23+
if (result[shellKey] !== undefined) result.shell = result[shellKey]!;
24+
if (result[shellArgsKey] !== undefined) result.shellArgs = result[shellArgsKey]!;
25+
if (result[envKey] !== undefined) result.env = {...(result.env || {}), ...result[envKey]};
26+
27+
return result;
28+
};

test/unit/config-platform.test.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import test from 'ava';
2+
3+
import {resolvePlatformConfig} from '../../app/utils/resolve-platform-config';
4+
5+
const baseConfig = () => ({
6+
shell: '/bin/sh',
7+
shellArgs: ['--login'],
8+
env: {BASE: '1'},
9+
updateChannel: 'stable' as const,
10+
autoUpdatePlugins: true,
11+
defaultSSHApp: true,
12+
disableAutoUpdates: false,
13+
useConpty: undefined,
14+
backgroundColor: '#000',
15+
bell: 'SOUND' as const,
16+
bellSound: null,
17+
bellSoundURL: null,
18+
borderColor: '#333',
19+
colors: {} as any,
20+
copyOnSelect: false,
21+
css: '',
22+
cursorAccentColor: '#000',
23+
cursorBlink: false,
24+
cursorColor: '#fff',
25+
cursorShape: 'BLOCK' as const,
26+
disableLigatures: true,
27+
fontFamily: 'monospace',
28+
fontSize: 12,
29+
fontWeight: 'normal' as const,
30+
fontWeightBold: 'bold' as const,
31+
foregroundColor: '#fff',
32+
imageSupport: false,
33+
letterSpacing: 0,
34+
lineHeight: 1,
35+
macOptionSelectionMode: 'vertical',
36+
padding: '12px',
37+
preserveCWD: true,
38+
quickEdit: false,
39+
screenReaderMode: false,
40+
scrollback: 1000,
41+
selectionColor: 'rgba(0,0,0,0.3)',
42+
showHamburgerMenu: '' as const,
43+
showWindowControls: '' as const,
44+
termCSS: '',
45+
webGLRenderer: false,
46+
webLinksActivationKey: '' as const,
47+
workingDirectory: '',
48+
defaultProfile: 'default',
49+
profiles: []
50+
});
51+
52+
test('resolvePlatformConfig: linux uses shellLinux', (t) => {
53+
const cfg = {...baseConfig(), shellLinux: '/bin/bash'};
54+
const result = resolvePlatformConfig(cfg, 'linux');
55+
t.is(result.shell, '/bin/bash');
56+
});
57+
58+
test('resolvePlatformConfig: darwin uses shellOsx', (t) => {
59+
const cfg = {...baseConfig(), shellOsx: '/bin/zsh'};
60+
const result = resolvePlatformConfig(cfg, 'darwin');
61+
t.is(result.shell, '/bin/zsh');
62+
});
63+
64+
test('resolvePlatformConfig: win32 uses shellWindows', (t) => {
65+
const cfg = {...baseConfig(), shellWindows: 'C:\\Windows\\System32\\cmd.exe'};
66+
const result = resolvePlatformConfig(cfg, 'win32');
67+
t.is(result.shell, 'C:\\Windows\\System32\\cmd.exe');
68+
});
69+
70+
test('resolvePlatformConfig: shellArgsLinux overrides shellArgs', (t) => {
71+
const cfg = {...baseConfig(), shellArgsLinux: ['-i']};
72+
const result = resolvePlatformConfig(cfg, 'linux');
73+
t.deepEqual(result.shellArgs, ['-i']);
74+
});
75+
76+
test('resolvePlatformConfig: empty shellArgsWindows overrides shellArgs', (t) => {
77+
const cfg = {...baseConfig(), shellArgsWindows: []};
78+
const result = resolvePlatformConfig(cfg, 'win32');
79+
t.deepEqual(result.shellArgs, []);
80+
});
81+
82+
test('resolvePlatformConfig: envLinux is merged with env', (t) => {
83+
const cfg = {...baseConfig(), env: {BASE: '1', SHARED: 'x'}, envLinux: {LINUX_ONLY: 'y', SHARED: 'z'}};
84+
const result = resolvePlatformConfig(cfg, 'linux');
85+
t.deepEqual(result.env, {BASE: '1', SHARED: 'z', LINUX_ONLY: 'y'});
86+
});
87+
88+
test('resolvePlatformConfig: envOsx does not affect linux', (t) => {
89+
const cfg = {...baseConfig(), envOsx: {MAC_ONLY: '1'}};
90+
const result = resolvePlatformConfig(cfg, 'linux');
91+
t.is(result.env['MAC_ONLY'], undefined);
92+
});
93+
94+
test('resolvePlatformConfig: no platform-specific keys leaves config unchanged', (t) => {
95+
const cfg = baseConfig();
96+
const result = resolvePlatformConfig(cfg, 'linux');
97+
t.is(result.shell, '/bin/sh');
98+
t.deepEqual(result.shellArgs, ['--login']);
99+
t.deepEqual(result.env, {BASE: '1'});
100+
});
101+
102+
test('resolvePlatformConfig: unsupported platform returns config unchanged', (t) => {
103+
const cfg = {...baseConfig(), shellLinux: '/bin/bash'};
104+
const result = resolvePlatformConfig(cfg, 'freebsd' as NodeJS.Platform);
105+
t.is(result.shell, '/bin/sh');
106+
});
107+
108+
test('resolvePlatformConfig: empty string shellWindows still overrides shell', (t) => {
109+
const cfg = {...baseConfig(), shellWindows: ''};
110+
const result = resolvePlatformConfig(cfg, 'win32');
111+
t.is(result.shell, '');
112+
});

typings/config.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ type profileConfigOptions = {
8282
disableLigatures: boolean;
8383
/** for environment variables */
8484
env: {[k: string]: string};
85+
/** platform-specific env override for Linux (merged with `env` on Linux) */
86+
envLinux?: {[k: string]: string};
87+
/** platform-specific env override for macOS (merged with `env` on macOS) */
88+
envOsx?: {[k: string]: string};
89+
/** platform-specific env override for Windows (merged with `env` on Windows) */
90+
envWindows?: {[k: string]: string};
8591
/** font family with optional fallbacks */
8692
fontFamily: string;
8793
/** default font size in pixels for all tabs */
@@ -153,11 +159,23 @@ type profileConfigOptions = {
153159
* Then Add `--command=usr/bin/bash.exe` to shellArgs
154160
*/
155161
shell: string;
162+
/** platform-specific shell override for Linux (overrides `shell` on Linux) */
163+
shellLinux?: string;
164+
/** platform-specific shell override for macOS (overrides `shell` on macOS) */
165+
shellOsx?: string;
166+
/** platform-specific shell override for Windows (overrides `shell` on Windows) */
167+
shellWindows?: string;
156168
/**
157169
* for setting shell arguments (e.g. for using interactive shellArgs: `['-i']`)
158170
* by default `['--login']` will be used
159171
*/
160172
shellArgs: string[];
173+
/** platform-specific shellArgs override for Linux (overrides `shellArgs` on Linux) */
174+
shellArgsLinux?: string[];
175+
/** platform-specific shellArgs override for macOS (overrides `shellArgs` on macOS) */
176+
shellArgsOsx?: string[];
177+
/** platform-specific shellArgs override for Windows (overrides `shellArgs` on Windows) */
178+
shellArgsWindows?: string[];
161179
/**
162180
* if you're using a Linux setup which show native menus, set to false
163181
*

0 commit comments

Comments
 (0)