Skip to content

Commit bc78490

Browse files
committed
Use XDF_CONFIG_HOME for fish config when available
Fixes #1158
1 parent dfe1bf8 commit bc78490

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/features/terminal/shells/fish/fishStartup.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ async function isFishInstalled(): Promise<boolean> {
1919
}
2020
}
2121

22-
async function getFishProfile(): Promise<string> {
23-
const homeDir = os.homedir();
24-
// Fish configuration is typically at ~/.config/fish/config.fish
25-
const profilePath = path.join(homeDir, '.config', 'fish', 'config.fish');
22+
/**
23+
* Resolve the Fish configuration profile path, honoring XDG_CONFIG_HOME when set.
24+
*/
25+
export async function getFishProfile(): Promise<string> {
26+
const xdgConfigHome = process.env.XDG_CONFIG_HOME?.trim() ?? '';
27+
const baseConfigDir = xdgConfigHome.length > 0 ? xdgConfigHome : path.join(os.homedir(), '.config');
28+
// Fish configuration is typically at $XDG_CONFIG_HOME/fish/config.fish or ~/.config/fish/config.fish
29+
const profilePath = path.join(baseConfigDir, 'fish', 'config.fish');
2630
traceInfo(`SHELL: fish profile found at: ${profilePath}`);
2731
return profilePath;
2832
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as assert from 'assert';
2+
import * as os from 'os';
3+
import * as path from 'path';
4+
import * as sinon from 'sinon';
5+
6+
import { getFishProfile } from '../../../../features/terminal/shells/fish/fishStartup';
7+
8+
suite('Fish Startup', () => {
9+
let originalXdgConfigHome: string | undefined;
10+
11+
setup(() => {
12+
originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
13+
});
14+
15+
teardown(() => {
16+
if (originalXdgConfigHome === undefined) {
17+
delete process.env.XDG_CONFIG_HOME;
18+
} else {
19+
process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
20+
}
21+
sinon.restore();
22+
});
23+
24+
test('getFishProfile uses XDG_CONFIG_HOME when set', async () => {
25+
const xdgConfigHome = path.join('test', 'xdg');
26+
process.env.XDG_CONFIG_HOME = xdgConfigHome;
27+
28+
const profilePath = await getFishProfile();
29+
30+
assert.strictEqual(profilePath, path.join(xdgConfigHome, 'fish', 'config.fish'));
31+
});
32+
33+
test('getFishProfile falls back to ~/.config when XDG_CONFIG_HOME is empty', async () => {
34+
process.env.XDG_CONFIG_HOME = ' ';
35+
const homeDir = os.homedir();
36+
37+
const profilePath = await getFishProfile();
38+
39+
assert.strictEqual(profilePath, path.join(homeDir, '.config', 'fish', 'config.fish'));
40+
});
41+
});

0 commit comments

Comments
 (0)