mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-22 12:29:53 +00:00
attempt to detect CWD on classic windows shells
This commit is contained in:
parent
211566488d
commit
21d533c7cf
@ -25,6 +25,8 @@ export interface IChildProcess {
|
|||||||
command: string
|
command: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const windowsDirectoryRegex = /([a-zA-Z]:[^\:\[\]\?\"\<\>\|]+)/mi // tslint:disable-line
|
||||||
|
|
||||||
export abstract class BaseSession {
|
export abstract class BaseSession {
|
||||||
open: boolean
|
open: boolean
|
||||||
name: string
|
name: string
|
||||||
@ -75,6 +77,7 @@ export abstract class BaseSession {
|
|||||||
export class Session extends BaseSession {
|
export class Session extends BaseSession {
|
||||||
private pty: any
|
private pty: any
|
||||||
private pauseAfterExit = false
|
private pauseAfterExit = false
|
||||||
|
private guessedCWD: string
|
||||||
|
|
||||||
constructor (private config: ConfigService) {
|
constructor (private config: ConfigService) {
|
||||||
super()
|
super()
|
||||||
@ -110,6 +113,8 @@ export class Session extends BaseSession {
|
|||||||
experimentalUseConpty: this.config.store.terminal.useConPTY,
|
experimentalUseConpty: this.config.store.terminal.useConPTY,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.guessedCWD = options.cwd || process.env.HOME
|
||||||
|
|
||||||
this.truePID = (this.pty as any).pid
|
this.truePID = (this.pty as any).pid
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
@ -125,6 +130,9 @@ export class Session extends BaseSession {
|
|||||||
|
|
||||||
this.pty.on('data-buffered', data => {
|
this.pty.on('data-buffered', data => {
|
||||||
this.emitOutput(data)
|
this.emitOutput(data)
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
this.guessWindowsCWD(data)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.pty.on('exit', () => {
|
this.pty.on('exit', () => {
|
||||||
@ -243,8 +251,18 @@ export class Session extends BaseSession {
|
|||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
return fs.readlink(`/proc/${this.truePID}/cwd`)
|
return fs.readlink(`/proc/${this.truePID}/cwd`)
|
||||||
}
|
}
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
return this.guessedCWD
|
||||||
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private guessWindowsCWD (data: string) {
|
||||||
|
let match = windowsDirectoryRegex.exec(data)
|
||||||
|
if (match) {
|
||||||
|
this.guessedCWD = match[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user