Add a keyboard shortcut to open the kitty shell

This commit is contained in:
Kovid Goyal 2018-04-06 14:59:13 +05:30
parent a97174a350
commit b64bceac7f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 34 additions and 7 deletions

View File

@ -13,6 +13,7 @@
:sc_fourth_window: pass:quotes[`ctrl+shift+4`] :sc_fourth_window: pass:quotes[`ctrl+shift+4`]
:sc_increase_font_size: pass:quotes[`ctrl+shift+equal`] :sc_increase_font_size: pass:quotes[`ctrl+shift+equal`]
:sc_input_unicode_character: pass:quotes[`ctrl+shift+u`] :sc_input_unicode_character: pass:quotes[`ctrl+shift+u`]
:sc_kitty_shell_window: pass:quotes[`ctrl+shift+escape`]
:sc_move_tab_backward: pass:quotes[`ctrl+shift+,`] :sc_move_tab_backward: pass:quotes[`ctrl+shift+,`]
:sc_move_tab_forward: pass:quotes[`ctrl+shift+.`] :sc_move_tab_forward: pass:quotes[`ctrl+shift+.`]
:sc_move_window_backward: pass:quotes[`ctrl+shift+b`] :sc_move_window_backward: pass:quotes[`ctrl+shift+b`]
@ -240,6 +241,7 @@ windows are:
|Click URL using the keyboard | {sc_run_simple_kitten_text_url_hints} |Click URL using the keyboard | {sc_run_simple_kitten_text_url_hints}
|Pass current selection to program | {sc_pass_selection_to_program} |Pass current selection to program | {sc_pass_selection_to_program}
|Edit kitty config file | {sc_edit_config_file} |Edit kitty config file | {sc_edit_config_file}
|Open a kitty shell | {sc_kitty_shell}
|=== |===

View File

@ -120,6 +120,7 @@ class Boss:
self.os_window_map[os_window_id] = tm self.os_window_map[os_window_id] = tm
if dpi_changed: if dpi_changed:
self.on_dpi_change(os_window_id) self.on_dpi_change(os_window_id)
return os_window_id
def list_os_windows(self): def list_os_windows(self):
for os_window_id, tm in self.os_window_map.items(): for os_window_id, tm in self.os_window_map.items():
@ -189,7 +190,7 @@ class Boss:
def _new_os_window(self, args, cwd_from=None): def _new_os_window(self, args, cwd_from=None):
sw = self.args_to_special_window(args, cwd_from) if args else None sw = self.args_to_special_window(args, cwd_from) if args else None
startup_session = create_session(self.opts, special_window=sw, cwd_from=cwd_from) startup_session = create_session(self.opts, special_window=sw, cwd_from=cwd_from)
self.add_os_window(startup_session) return self.add_os_window(startup_session)
def new_os_window(self, *args): def new_os_window(self, *args):
self._new_os_window(args) self._new_os_window(args)
@ -205,7 +206,7 @@ class Boss:
def _handle_remote_command(self, cmd, window=None): def _handle_remote_command(self, cmd, window=None):
response = None response = None
if self.opts.allow_remote_control: if self.opts.allow_remote_control or getattr(window, 'allow_remote_control', False):
try: try:
response = handle_cmd(self, window, cmd) response = handle_cmd(self, window, cmd)
except Exception as err: except Exception as err:
@ -552,6 +553,25 @@ class Boss:
cmd = json.loads(output.partition(' ')[2].strip()) cmd = json.loads(output.partition(' ')[2].strip())
open_url(cmd['url'], cmd['program']) open_url(cmd['url'], cmd['program'])
def kitty_shell(self, window_type):
cmd = ['kitty', '@']
if window_type == 'tab':
window = self._new_tab(cmd).active_window
elif window_type == 'os_window':
os_window_id = self._new_os_window(cmd)
window = self.os_window_map[os_window_id].active_window
elif window_type == 'overlay':
w = self.active_window
tab = self.active_tab
if w is not None and tab is not None and w.overlay_for is None:
window = tab.new_special_window(SpecialWindow(cmd, overlay_for=w.id))
else:
window = None
else:
window = self._new_window(cmd)
if window is not None:
window.allow_remote_control = True
def switch_focus_to(self, window_idx): def switch_focus_to(self, window_idx):
tab = self.active_tab tab = self.active_tab
tab.set_active_window_idx(window_idx) tab.set_active_window_idx(window_idx)
@ -661,7 +681,7 @@ class Boss:
special_window = self.args_to_special_window(args, cwd_from=cwd_from) special_window = self.args_to_special_window(args, cwd_from=cwd_from)
tm = self.active_tab_manager tm = self.active_tab_manager
if tm is not None: if tm is not None:
tm.new_tab(special_window=special_window, cwd_from=cwd_from) return tm.new_tab(special_window=special_window, cwd_from=cwd_from)
def new_tab(self, *args): def new_tab(self, *args):
self._new_tab(args) self._new_tab(args)
@ -675,9 +695,9 @@ class Boss:
tab = self.active_tab tab = self.active_tab
if tab is not None: if tab is not None:
if args: if args:
tab.new_special_window(self.args_to_special_window(args, cwd_from=cwd_from)) return tab.new_special_window(self.args_to_special_window(args, cwd_from=cwd_from))
else: else:
tab.new_window(cwd_from=cwd_from) return tab.new_window(cwd_from=cwd_from)
def new_window(self, *args): def new_window(self, *args):
self._new_window(args) self._new_window(args)

View File

@ -112,7 +112,7 @@ def parse_key_action(action):
args = rest.split(' ', 2) args = rest.split(' ', 2)
elif func == 'goto_tab': elif func == 'goto_tab':
args = (max(0, int(rest)), ) args = (max(0, int(rest)), )
elif func == 'goto_layout': elif func == 'goto_layout' or func == 'kitty_shell':
args = [rest] args = [rest]
elif func == 'set_font_size': elif func == 'set_font_size':
args = (float(rest),) args = (float(rest),)

View File

@ -437,6 +437,8 @@ map ctrl+shift+f2 edit_config_file
# url_hints. For example: # url_hints. For example:
# map ctrl+shift+e run_simple_kitten text url_hints --program firefox --regex "http://[^ ]+" # map ctrl+shift+e run_simple_kitten text url_hints --program firefox --regex "http://[^ ]+"
map ctrl+shift+e run_simple_kitten text url_hints map ctrl+shift+e run_simple_kitten text url_hints
# Open the kitty shell in a new window/tab/overlay/os_window to control kitty using commands.
map ctrl+shift+escape kitty_shell window
# Sending arbitrary text on shortcut key presses # Sending arbitrary text on shortcut key presses
# You can tell kitty to send arbitrary (UTF-8) encoded text to # You can tell kitty to send arbitrary (UTF-8) encoded text to

View File

@ -143,6 +143,8 @@ def run_cmd(global_opts, cmd, func, opts, items):
def real_main(global_opts): def real_main(global_opts):
readline.read_init_file() readline.read_init_file()
print_help_for_seq.allow_pager = False print_help_for_seq.allow_pager = False
print('Welcome to the kitty shell!')
print('Use {} for assistance or {} to quit'.format(green('help'), green('exit')))
while True: while True:
try: try:

View File

@ -467,6 +467,7 @@ class TabManager: # {{{
self._add_tab(Tab(self, special_window=special_window, cwd_from=cwd_from)) self._add_tab(Tab(self, special_window=special_window, cwd_from=cwd_from))
self._set_active_tab(idx) self._set_active_tab(idx)
self.update_tab_bar() self.update_tab_bar()
return self.tabs[idx]
def remove(self, tab): def remove(self, tab):
self._remove_tab(tab) self._remove_tab(tab)