Skip to content

Commit

Permalink
Add action to open a profile in a new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
fran-f committed Sep 8, 2021
1 parent 6d07fe9 commit 53192a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/lib/windows_terminal_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
24 changes: 20 additions & 4 deletions src/terminal_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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]
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 53192a0

Please sign in to comment.