Add a new shortcut to pass the current selection to an external program

This commit is contained in:
Kovid Goyal 2017-10-20 13:30:23 +05:30
parent f947c2eecb
commit 227d21184a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,8 @@
Changelog
==============
kitty is a modern, hackable, OpenGL based terminal emulator.
version 0.4.0 [future]
-----------------------
@ -31,3 +33,5 @@ version 0.4.0 [future]
the background color, for enhanced visibility.
- Allow combining multiple independent actions into a single shortcut
- Add a new shortcut to pass the current selection to an external program

View File

@ -94,6 +94,7 @@ def parse_shortcut(sc):
KeyAction = namedtuple('KeyAction', 'func args')
shlex_actions = {'pass_selection_to_program'}
def parse_key_action(action):
@ -106,6 +107,8 @@ def parse_key_action(action):
sep, rest = rest.split(' ', 1)
parts = re.split(r'\s*' + re.escape(sep) + r'\s*', rest)
args = tuple(map(parse_key_action, filter(None, parts)))
elif func in shlex_actions:
args = shlex.split(rest)
return KeyAction(func, args)

View File

@ -218,6 +218,7 @@ map ctrl+shift+v paste_from_clipboard
map ctrl+shift+s paste_from_selection
map ctrl+shift+c copy_to_clipboard
map shift+insert paste_from_selection
map ctrl+shift+o pass_selection_to_program
# Scrolling
map ctrl+shift+up scroll_line_up

View File

@ -23,7 +23,7 @@ from .fast_data_types import (
)
from .rgb import to_color
from .terminfo import get_capabilities
from .utils import color_as_int, load_shaders, parse_color_set, sanitize_title
from .utils import color_as_int, load_shaders, parse_color_set, sanitize_title, open_url, open_cmd
class DynamicColor(Enum):
@ -256,6 +256,14 @@ class Window:
if text:
get_boss().glfw_window.set_clipboard_string(text)
def pass_selection_to_program(self, *args):
text = self.text_for_selection()
if text:
if args:
open_cmd(args, text)
else:
open_url(text)
def scroll_line_up(self):
if self.screen.is_main_linebuf():
self.screen.scroll(SCROLL_LINE, True)