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_increase_font_size: pass:quotes[`ctrl+shift+equal`]
: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_forward: pass:quotes[`ctrl+shift+.`]
:sc_move_window_backward: pass:quotes[`ctrl+shift+b`]
@ -239,7 +240,8 @@ windows are:
|Input unicode character | {sc_input_unicode_character}
|Click URL using the keyboard | {sc_run_simple_kitten_text_url_hints}
|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 @@ def add_os_window(self, startup_session, os_window_id=None, wclass=None, wname=N
self.os_window_map[os_window_id] = tm
if dpi_changed:
self.on_dpi_change(os_window_id)
return os_window_id
def list_os_windows(self):
for os_window_id, tm in self.os_window_map.items():
@ -189,7 +190,7 @@ def set_active_window(self, window):
def _new_os_window(self, args, cwd_from=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)
self.add_os_window(startup_session)
return self.add_os_window(startup_session)
def new_os_window(self, *args):
self._new_os_window(args)
@ -205,7 +206,7 @@ def add_child(self, window):
def _handle_remote_command(self, cmd, window=None):
response = None
if self.opts.allow_remote_control:
if self.opts.allow_remote_control or getattr(window, 'allow_remote_control', False):
try:
response = handle_cmd(self, window, cmd)
except Exception as err:
@ -552,6 +553,25 @@ def open_hinted_url(self, source_window):
cmd = json.loads(output.partition(' ')[2].strip())
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):
tab = self.active_tab
tab.set_active_window_idx(window_idx)
@ -661,7 +681,7 @@ def _new_tab(self, args, cwd_from=None):
special_window = self.args_to_special_window(args, cwd_from=cwd_from)
tm = self.active_tab_manager
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):
self._new_tab(args)
@ -675,9 +695,9 @@ def _new_window(self, args, cwd_from=None):
tab = self.active_tab
if tab is not None:
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:
tab.new_window(cwd_from=cwd_from)
return tab.new_window(cwd_from=cwd_from)
def new_window(self, *args):
self._new_window(args)

View File

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

View File

@ -437,6 +437,8 @@ map ctrl+shift+f2 edit_config_file
# 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
# 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
# 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):
readline.read_init_file()
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:
try:

View File

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