Skip to content

Commit

Permalink
Initial fix for home detection for csh/tcsh shell (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Oct 6, 2021
1 parent 8402f92 commit db4c18c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export interface Connection {
}

async function tryGetHome(ssh: Client): Promise<string | null> {
const exec = await toPromise<ClientChannel>(cb => ssh.exec('echo "::sshfs:home:$(echo ~)\n"', cb));
const exec = await toPromise<ClientChannel>(cb => ssh.exec('echo "::sshfs:home:`echo ~`:"', cb));
let home = '';
exec.stdout.on('data', (chunk: any) => home += chunk);
await toPromise(cb => exec.on('close', cb));
if (!home) return null;
return home.match(/::sshfs:home:(.*?)\n/)?.[1] || null;
return home.match(/::sshfs:home:(.*?):/)?.[1] || null;
}

const TMP_PROFILE_SCRIPT = `
Expand Down Expand Up @@ -80,8 +80,9 @@ export class ConnectionManager {
protected async _createCommandTerminal(client: Client, authority: string, debugLogging: boolean): Promise<string> {
const logging = Logging.scope(`CmdTerm(${authority})`);
const shell = await toPromise<ClientChannel>(cb => client.shell({}, cb));
shell.write('echo ::sshfs:TTY:$(tty)\n');
shell.write('echo ::sshfs:TTY:`tty`\n');
return new Promise((resolvePath, rejectPath) => {
setTimeout(() => rejectPath(new Error('Timeout fetching command path')), 10e3);
const rl = readline.createInterface(shell.stdout);
shell.stdout.once('error', rejectPath);
shell.once('close', () => rejectPath());
Expand Down Expand Up @@ -168,6 +169,7 @@ export class ConnectionManager {
home = '';
}
}
logging.debug`Home path: ${home}`;
// Calculate the environment
const environment: EnvironmentVariable[] = mergeEnvironment([], config.environment);
// Set up stuff for receiving remote commands
Expand All @@ -181,6 +183,7 @@ export class ConnectionManager {
const sftp = await toPromise<SFTPWrapper>(cb => client.sftp(cb));
await toPromise(cb => sftp.writeFile('/tmp/.Kelvin_sshfs', TMP_PROFILE_SCRIPT, { mode: 0o666 }, cb));
}
logging.debug`Environment: ${environment}`;
// Set up the Connection object
let timeoutCounter = 0;
const con: Connection = {
Expand Down

0 comments on commit db4c18c

Please sign in to comment.