1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-23 18:44:20 +03:00

cache dscl output

This commit is contained in:
Eugene Pankov 2021-02-07 13:43:58 +01:00
parent 61a46e3b4a
commit 6bad2a2167
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4

View File

@ -8,6 +8,8 @@ import { Shell } from '../api/interfaces'
/** @hidden */
@Injectable()
export class MacOSDefaultShellProvider extends ShellProvider {
private cachedShell?: string
constructor (
private hostApp: HostAppService,
) {
@ -18,14 +20,29 @@ export class MacOSDefaultShellProvider extends ShellProvider {
if (this.hostApp.platform !== Platform.macOS) {
return []
}
const shellEntry = (await exec(`/usr/bin/dscl . -read /Users/${process.env.LOGNAME} UserShell`))[0].toString()
return [{
id: 'default',
name: 'User default',
command: shellEntry.split(' ')[1].trim(),
command: await this.getDefaultShellCached(),
args: ['--login'],
hidden: true,
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()
}
}