From 227d21184a748080940a5536bbd372868c759ed3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 20 Oct 2017 13:30:23 +0530 Subject: [PATCH] Add a new shortcut to pass the current selection to an external program --- CHANGELOG.rst | 4 ++++ kitty/config.py | 3 +++ kitty/kitty.conf | 1 + kitty/window.py | 10 +++++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 57a30b6a5..2394a4020 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/kitty/config.py b/kitty/config.py index 4504ed6ac..040a657bb 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -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) diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 5f5958429..5220ae936 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -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 diff --git a/kitty/window.py b/kitty/window.py index 1eebcb700..094249ec4 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -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)