diff --git a/kitty/boss.py b/kitty/boss.py index 91162ed8b..b565bd270 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -331,6 +331,11 @@ class Boss: if text: set_primary_selection(text) + def goto_tab(self, tab_num): + tm = self.active_tab_manager + if tm is not None: + tm.goto_tab(tab_num - 1) + def next_tab(self): tm = self.active_tab_manager if tm is not None: diff --git a/kitty/config.py b/kitty/config.py index 80157bbdb..922ab8d4a 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -109,6 +109,8 @@ def parse_key_action(action): args = tuple(map(parse_key_action, filter(None, parts))) elif func == 'send_text': args = rest.split(' ', 1) + elif func == 'goto_tab': + args = (max(0, int(rest)),) elif func in shlex_actions: args = shlex.split(rest) return KeyAction(func, args) @@ -338,7 +340,7 @@ with open( defaults = parse_config(f.readlines(), check_keys=False) Options = namedtuple('Defaults', ','.join(defaults.keys())) defaults = Options(**defaults) -actions = frozenset(a.func for a in defaults.keymap.values()) | frozenset({'combine', 'send_text'}) +actions = frozenset(a.func for a in defaults.keymap.values()) | frozenset({'combine', 'send_text', 'goto_tab'}) no_op_actions = frozenset({'noop', 'no-op', 'no_op'}) diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 267f09291..443efb1b1 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -294,6 +294,10 @@ map ctrl+shift+q close_tab map ctrl+shift+l next_layout map ctrl+shift+. move_tab_forward map ctrl+shift+, move_tab_backward +# You can also create shortcuts to go to specific tabs, with 1 being the first tab +# map ctrl+alt+1 goto_tab 1 +# map ctrl+alt+2 goto_tab 2 + # Just as with new_window above, you can also pass the name of arbitrary # commands to run when using new_tab. diff --git a/kitty/tabs.py b/kitty/tabs.py index b977a3348..bc884e667 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -360,6 +360,10 @@ class TabManager: # {{{ if len(self.tabs) > 1: self.set_active_tab((self.active_tab_idx + len(self.tabs) + delta) % len(self.tabs)) + def goto_tab(self, tab_num): + if tab_num < len(self.tabs) and 0 <= tab_num: + self.set_active_tab(tab_num) + def __iter__(self): return iter(self.tabs)