mirror of
https://github.com/Eugeny/tabby.git
synced 2025-09-24 09:06:03 +00:00
cache dscl output
This commit is contained in:
@@ -8,6 +8,8 @@ import { Shell } from '../api/interfaces'
|
|||||||
/** @hidden */
|
/** @hidden */
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MacOSDefaultShellProvider extends ShellProvider {
|
export class MacOSDefaultShellProvider extends ShellProvider {
|
||||||
|
private cachedShell?: string
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private hostApp: HostAppService,
|
private hostApp: HostAppService,
|
||||||
) {
|
) {
|
||||||
@@ -18,14 +20,29 @@ export class MacOSDefaultShellProvider extends ShellProvider {
|
|||||||
if (this.hostApp.platform !== Platform.macOS) {
|
if (this.hostApp.platform !== Platform.macOS) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const shellEntry = (await exec(`/usr/bin/dscl . -read /Users/${process.env.LOGNAME} UserShell`))[0].toString()
|
|
||||||
return [{
|
return [{
|
||||||
id: 'default',
|
id: 'default',
|
||||||
name: 'User default',
|
name: 'User default',
|
||||||
command: shellEntry.split(' ')[1].trim(),
|
command: await this.getDefaultShellCached(),
|
||||||
args: ['--login'],
|
args: ['--login'],
|
||||||
hidden: true,
|
hidden: true,
|
||||||
env: {},
|
env: {},
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getDefaultShellCached () {
|
||||||
|
if (!this.cachedShell) {
|
||||||
|
this.cachedShell = await this.getDefaultShell()
|
||||||
|
} else {
|
||||||
|
this.getDefaultShell().then(shell => {
|
||||||
|
this.cachedShell = shell
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return this.cachedShell!
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getDefaultShell () {
|
||||||
|
const shellEntry = (await exec(`/usr/bin/dscl . -read /Users/${process.env.LOGNAME} UserShell`))[0].toString()
|
||||||
|
return shellEntry.split(' ')[1].trim()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user