diff --git a/app/lib/cli.ts b/app/lib/cli.ts index 5d68ac64..2328eba7 100644 --- a/app/lib/cli.ts +++ b/app/lib/cli.ts @@ -13,6 +13,9 @@ export function parseArgs (argv, cwd) { .command('run [command...]', 'run a command in the terminal', { command: { type: 'string' }, }) + .command('profile [profileName]', 'open a tab with specified profile', { + profileName: { type: 'string' }, + }) .command('paste [text]', 'paste stdin into the active tab', yargs => { return yargs.option('escape', { alias: 'e', diff --git a/terminus-core/src/services/hostApp.service.ts b/terminus-core/src/services/hostApp.service.ts index cf863e51..d7ed0b24 100644 --- a/terminus-core/src/services/hostApp.service.ts +++ b/terminus-core/src/services/hostApp.service.ts @@ -27,6 +27,7 @@ export class HostAppService { private cliOpenDirectory = new Subject() private cliRunCommand = new Subject() private cliPaste = new Subject() + private cliOpenProfile = new Subject() private configChangeBroadcast = new Subject() private windowCloseRequest = new Subject() private logger: Logger @@ -37,6 +38,7 @@ export class HostAppService { get cliOpenDirectory$ (): Observable { return this.cliOpenDirectory } get cliRunCommand$ (): Observable { return this.cliRunCommand } get cliPaste$ (): Observable { return this.cliPaste } + get cliOpenProfile$ (): Observable { return this.cliOpenProfile } get configChangeBroadcast$ (): Observable { return this.configChangeBroadcast } get windowCloseRequest$ (): Observable { return this.windowCloseRequest } @@ -91,6 +93,8 @@ export class HostAppService { text = shellEscape([text]) } this.cliPaste.next(text) + } else if (op === 'profile') { + this.cliOpenProfile.next(argv.profileName) } else { this.secondInstance.next() } diff --git a/terminus-terminal/src/index.ts b/terminus-terminal/src/index.ts index d8b30dfb..e7da5652 100644 --- a/terminus-terminal/src/index.ts +++ b/terminus-terminal/src/index.ts @@ -164,6 +164,7 @@ export default class TerminalModule { } } }) + hostApp.cliOpenDirectory$.subscribe(async directory => { if (await fs.exists(directory)) { if ((await fs.stat(directory)).isDirectory()) { @@ -172,6 +173,7 @@ export default class TerminalModule { } } }) + hostApp.cliRunCommand$.subscribe(async command => { terminal.openTab({ id: '', @@ -180,6 +182,7 @@ export default class TerminalModule { }, null, true) hostApp.bringToFront() }) + hostApp.cliPaste$.subscribe(text => { if (app.activeTab instanceof TerminalTabComponent && app.activeTab.session) { (app.activeTab as TerminalTabComponent).sendInput(text) @@ -187,6 +190,16 @@ export default class TerminalModule { } }) + hostApp.cliOpenProfile$.subscribe(async profileName => { + let profile = config.store.terminal.profiles.find(x => x.name === profileName) + if (!profile) { + console.error('Requested profile', profileName, 'not found') + return + } + terminal.openTabWithOptions(profile.sessionOptions) + hostApp.bringToFront() + }) + dockMenu.update() } }