From 53192a05bcc8ec9f333c72599891cca517eaaa20 Mon Sep 17 00:00:00 2001 From: Francesco Figari Date: Wed, 8 Sep 2021 20:30:52 +0100 Subject: [PATCH] Add action to open a profile in a new tab --- src/lib/windows_terminal_wrapper.py | 3 +++ src/terminal_profiles.py | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/lib/windows_terminal_wrapper.py b/src/lib/windows_terminal_wrapper.py index 598e891..29dc051 100644 --- a/src/lib/windows_terminal_wrapper.py +++ b/src/lib/windows_terminal_wrapper.py @@ -53,3 +53,6 @@ def openprofile(self, guid, elevate=False): ) else: kpu.shell_execute(self._wt_executable, args=['--profile', guid]) + + def opennewtab(self, guid): + kpu.shell_execute(self._wt_executable, args=['--window', '0', '--profile', guid]) diff --git a/src/terminal_profiles.py b/src/terminal_profiles.py index fd8d13d..64ccb19 100644 --- a/src/terminal_profiles.py +++ b/src/terminal_profiles.py @@ -24,6 +24,11 @@ class TerminalProfiles(kp.Plugin): 'label' : "Open", 'short_desc' : "Open this profile in a new window" } + ACTION_OPEN_NEW_TAB = { + 'name' : "wt.open_new_tab", + 'label' : "Open new tab", + 'short_desc' : "Open this profile in a new tab of an existing window" + } ACTION_ELEVATE = { 'name' : "wt.elevate", 'label' : "Run as Administrator", @@ -43,7 +48,11 @@ def on_start(self): self._load_settings() self._set_up() - actions = [self.ACTION_OPEN, self.ACTION_ELEVATE] + actions = [ + self.ACTION_OPEN, + self.ACTION_OPEN_NEW_TAB, + self.ACTION_ELEVATE, + ] self.set_actions( kp.ItemCategory.REFERENCE, [self.create_action(**a) for a in actions] @@ -72,9 +81,16 @@ def on_execute(self, item, action): [instance, _, profile] = item.target().partition(self.INSTANCE_SEPARATOR) terminal = self.terminal_instances[instance]["wrapper"] - is_elevate = action is not None and \ - action.name() == self.ACTION_ELEVATE['name'] - terminal.openprofile(profile, is_elevate) + if action is None: + terminal.openprofile(profile) + return + + if action.name() == self.ACTION_ELEVATE['name']: + terminal.openprofile(profile, elevate=True) + elif action.name() == self.ACTION_OPEN_NEW_TAB['name']: + terminal.opennewtab(profile) + else: + terminal.openprofile(profile) def on_suggest(self, user_input, items_chain): """Respond to on_suggest Keypirinha messages"""