From 21d533c7cf09f1650eaa0db75185cc7513644397 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sat, 22 Dec 2018 01:36:05 +0100 Subject: [PATCH] attempt to detect CWD on classic windows shells --- .../src/services/sessions.service.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/terminus-terminal/src/services/sessions.service.ts b/terminus-terminal/src/services/sessions.service.ts index fb6a0458..72d5eb69 100644 --- a/terminus-terminal/src/services/sessions.service.ts +++ b/terminus-terminal/src/services/sessions.service.ts @@ -25,6 +25,8 @@ export interface IChildProcess { command: string } +const windowsDirectoryRegex = /([a-zA-Z]:[^\:\[\]\?\"\<\>\|]+)/mi // tslint:disable-line + export abstract class BaseSession { open: boolean name: string @@ -75,6 +77,7 @@ export abstract class BaseSession { export class Session extends BaseSession { private pty: any private pauseAfterExit = false + private guessedCWD: string constructor (private config: ConfigService) { super() @@ -110,6 +113,8 @@ export class Session extends BaseSession { experimentalUseConpty: this.config.store.terminal.useConPTY, }) + this.guessedCWD = options.cwd || process.env.HOME + this.truePID = (this.pty as any).pid setTimeout(async () => { @@ -125,6 +130,9 @@ export class Session extends BaseSession { this.pty.on('data-buffered', data => { this.emitOutput(data) + if (process.platform === 'win32') { + this.guessWindowsCWD(data) + } }) this.pty.on('exit', () => { @@ -243,8 +251,18 @@ export class Session extends BaseSession { if (process.platform === 'linux') { return fs.readlink(`/proc/${this.truePID}/cwd`) } + if (process.platform === 'win32') { + return this.guessedCWD + } return null } + + private guessWindowsCWD (data: string) { + let match = windowsDirectoryRegex.exec(data) + if (match) { + this.guessedCWD = match[0] + } + } } @Injectable({ providedIn: 'root' })