diff --git a/app/commands.ts b/app/commands.ts index 10cb98e4f37a..2b2ba795a2b2 100644 --- a/app/commands.ts +++ b/app/commands.ts @@ -145,6 +145,19 @@ const commands: Record void> = { }; }); +//Profile specific commands +getConfig().profiles.forEach((profile) => { + commands[`tab:new:${profile.name}`] = (focusedWindow) => { + focusedWindow?.rpc.emit('termgroup add req', {profile: profile.name}); + }; + commands[`pane:splitRight:${profile.name}`] = (focusedWindow) => { + focusedWindow?.rpc.emit('split request vertical', {profile: profile.name}); + }; + commands[`pane:splitDown:${profile.name}`] = (focusedWindow) => { + focusedWindow?.rpc.emit('split request horizontal', {profile: profile.name}); + }; +}); + export const execCommand = (command: string, focusedWindow?: BrowserWindow) => { const fn = commands[command]; if (fn) { diff --git a/app/menus/menu.ts b/app/menus/menu.ts index 45c3e09cb248..93bb95ed06a1 100644 --- a/app/menus/menu.ts +++ b/app/menus/menu.ts @@ -62,7 +62,11 @@ export const createMenu = ( }; const menu = [ ...(process.platform === 'darwin' ? [darwinMenu(commandKeys, execCommand, showAbout)] : []), - shellMenu(commandKeys, execCommand), + shellMenu( + commandKeys, + execCommand, + getConfig().profiles.map((p) => p.name) + ), editMenu(commandKeys, execCommand), viewMenu(commandKeys, execCommand), toolsMenu(commandKeys, execCommand), diff --git a/app/menus/menus/shell.ts b/app/menus/menus/shell.ts index c7f5a41b52b5..99d657239c25 100644 --- a/app/menus/menus/shell.ts +++ b/app/menus/menus/shell.ts @@ -2,7 +2,8 @@ import type {BrowserWindow, MenuItemConstructorOptions} from 'electron'; export default ( commandKeys: Record, - execCommand: (command: string, focusedWindow?: BrowserWindow) => void + execCommand: (command: string, focusedWindow?: BrowserWindow) => void, + profiles: string[] ): MenuItemConstructorOptions => { const isMac = process.platform === 'darwin'; @@ -43,6 +44,37 @@ export default ( { type: 'separator' }, + ...profiles.map( + (profile): MenuItemConstructorOptions => ({ + label: profile, + submenu: [ + { + label: 'New Tab', + click(item, focusedWindow) { + execCommand(`tab:new:${profile}`, focusedWindow); + } + }, + { + type: 'separator' + }, + { + label: 'Split Down', + click(item, focusedWindow) { + execCommand(`pane:splitDown:${profile}`, focusedWindow); + } + }, + { + label: 'Split Right', + click(item, focusedWindow) { + execCommand(`pane:splitRight:${profile}`, focusedWindow); + } + } + ] + }) + ), + { + type: 'separator' + }, { label: 'Close', accelerator: commandKeys['pane:close'], diff --git a/app/ui/contextmenu.ts b/app/ui/contextmenu.ts index 7a0824802089..5f0bc73d6c8a 100644 --- a/app/ui/contextmenu.ts +++ b/app/ui/contextmenu.ts @@ -3,6 +3,7 @@ import shellMenu from '../menus/menus/shell'; import {execCommand} from '../commands'; import {getDecoratedKeymaps} from '../plugins'; import type {MenuItemConstructorOptions, BrowserWindow} from 'electron'; +import {getProfiles} from '../config'; const separator: MenuItemConstructorOptions = {type: 'separator'}; const getCommandKeys = (keymaps: Record): Record => @@ -25,7 +26,11 @@ export default ( selection: string ) => { const commandKeys = getCommandKeys(getDecoratedKeymaps()); - const _shell = shellMenu(commandKeys, execCommand).submenu as MenuItemConstructorOptions[]; + const _shell = shellMenu( + commandKeys, + execCommand, + getProfiles().map((p) => p.name) + ).submenu as MenuItemConstructorOptions[]; const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection)); return _edit .concat(separator, _shell)