Resolve VS Code config paths beside SSH config
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s

This commit is contained in:
DuProcess
2026-07-16 22:41:05 -04:00
parent d471d9576a
commit 569a3e9ce5
2 changed files with 41 additions and 3 deletions
+19 -3
View File
@@ -84,12 +84,13 @@ async function configureHost() {
});
const sshDir = path.join(os.homedir(), '.ssh');
fs.mkdirSync(sshDir, { recursive: true });
const generatedPath = expandHomePath(
const mainConfig = path.join(sshDir, 'config');
const generatedPath = resolveGeneratedSshConfigPath(
mainConfig,
config.get('generatedSshConfig') || path.join(sshDir, 'config.dosh'),
os.homedir(),
process.platform
);
const mainConfig = path.join(sshDir, 'config');
ensureInclude(mainConfig, sshIncludeTarget(mainConfig, generatedPath, process.platform));
upsertBlock(generatedPath, alias, block);
return { alias, generatedPath };
@@ -143,6 +144,18 @@ function sshIncludeTarget(mainConfigPath, generatedPath, platform = process.plat
return sshConfigPathWord(includePath, platform);
}
function resolveGeneratedSshConfigPath(
mainConfigPath,
configuredPath,
home = os.homedir(),
platform = process.platform
) {
const pathApi = platform === 'win32' ? path.win32 : path;
const mainDir = pathApi.resolve(pathApi.dirname(mainConfigPath));
const expanded = expandHomePath(configuredPath, home, platform);
return pathApi.resolve(mainDir, expanded);
}
function upsertBlock(configPath, alias, block) {
const dir = path.dirname(configPath);
if (dir && dir !== '.') {
@@ -185,7 +198,9 @@ async function showSshConfig() {
const api = requireVscode();
const config = api.workspace.getConfiguration('dosh');
const sshDir = path.join(os.homedir(), '.ssh');
const generatedPath = expandHomePath(
const mainConfig = path.join(sshDir, 'config');
const generatedPath = resolveGeneratedSshConfigPath(
mainConfig,
config.get('generatedSshConfig') || path.join(sshDir, 'config.dosh'),
os.homedir(),
process.platform
@@ -270,6 +285,7 @@ module.exports = {
deactivate,
expandHomePath,
ensureInclude,
resolveGeneratedSshConfigPath,
sshBlock,
sshConfigPathWord,
shellQuote,
+22
View File
@@ -7,6 +7,7 @@ const path = require('node:path');
const {
expandHomePath,
ensureInclude,
resolveGeneratedSshConfigPath,
shellQuote,
sshBlock,
sshConfigPathWord,
@@ -101,6 +102,27 @@ test('home-relative generated config paths expand for POSIX and Windows', () =>
);
});
test('relative generated config paths resolve beside the main ssh config', () => {
assert.equal(
resolveGeneratedSshConfigPath(
'/Users/palav/.ssh/config',
'config.dosh',
'/Users/palav',
'darwin'
),
'/Users/palav/.ssh/config.dosh'
);
assert.equal(
resolveGeneratedSshConfigPath(
'C:\\Users\\palav\\.ssh\\config',
'dosh\\config.dosh',
'C:\\Users\\palav',
'win32'
),
'C:\\Users\\palav\\.ssh\\dosh\\config.dosh'
);
});
test('config writers create missing parent directories', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'dosh-vscode-'));
const mainConfig = path.join(root, 'ssh', 'config');