Add a keyboard shortcut to edit the kitty config file easily
Fixes #366
This commit is contained in:
parent
b3cc6f3802
commit
51b6b325b9
@ -39,6 +39,7 @@
|
|||||||
:sc_scroll_page_up: pass:quotes[`ctrl+shift+page_up`]
|
:sc_scroll_page_up: pass:quotes[`ctrl+shift+page_up`]
|
||||||
:sc_second_window: pass:quotes[`ctrl+shift+2`]
|
:sc_second_window: pass:quotes[`ctrl+shift+2`]
|
||||||
:sc_seventh_window: pass:quotes[`ctrl+shift+7`]
|
:sc_seventh_window: pass:quotes[`ctrl+shift+7`]
|
||||||
|
:sc_show_preferences: pass:quotes[`ctrl+shift+f2`]
|
||||||
:sc_show_scrollback: pass:quotes[`ctrl+shift+h`]
|
:sc_show_scrollback: pass:quotes[`ctrl+shift+h`]
|
||||||
:sc_sixth_window: pass:quotes[`ctrl+shift+6`]
|
:sc_sixth_window: pass:quotes[`ctrl+shift+6`]
|
||||||
:sc_tenth_window: pass:quotes[`ctrl+shift+0`]
|
:sc_tenth_window: pass:quotes[`ctrl+shift+0`]
|
||||||
@ -234,6 +235,7 @@ windows are:
|
|||||||
|Input unicode character | {sc_input_unicode_character}
|
|Input unicode character | {sc_input_unicode_character}
|
||||||
|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}
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shlex
|
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -11,7 +10,7 @@ from functools import lru_cache
|
|||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from kitty.config import cached_values_for
|
from kitty.config import cached_values_for
|
||||||
from kitty.constants import config_dir
|
from kitty.constants import config_dir, editor
|
||||||
from kitty.fast_data_types import wcswidth
|
from kitty.fast_data_types import wcswidth
|
||||||
from kitty.key_encoding import (
|
from kitty.key_encoding import (
|
||||||
DOWN, ESCAPE, F1, F2, F3, F4, F12, LEFT, RELEASE, RIGHT, SHIFT, TAB, UP,
|
DOWN, ESCAPE, F1, F2, F3, F4, F12, LEFT, RELEASE, RIGHT, SHIFT, TAB, UP,
|
||||||
@ -426,7 +425,6 @@ class UnicodeInput(Handler):
|
|||||||
if not os.path.exists(favorites_path):
|
if not os.path.exists(favorites_path):
|
||||||
with open(favorites_path, 'wb') as f:
|
with open(favorites_path, 'wb') as f:
|
||||||
f.write(serialize_favorites(load_favorites()).encode('utf-8'))
|
f.write(serialize_favorites(load_favorites()).encode('utf-8'))
|
||||||
editor = shlex.split(os.environ.get('EDITOR', 'vim'))
|
|
||||||
with self.suspend():
|
with self.suspend():
|
||||||
p = subprocess.Popen(editor + [favorites_path])
|
p = subprocess.Popen(editor + [favorites_path])
|
||||||
if p.wait() == 0:
|
if p.wait() == 0:
|
||||||
|
|||||||
@ -10,8 +10,10 @@ from gettext import gettext as _
|
|||||||
from weakref import WeakValueDictionary
|
from weakref import WeakValueDictionary
|
||||||
|
|
||||||
from .cli import create_opts, parse_args
|
from .cli import create_opts, parse_args
|
||||||
from .config import MINIMUM_FONT_SIZE, initial_window_size
|
from .config import (
|
||||||
from .constants import appname, set_boss
|
MINIMUM_FONT_SIZE, initial_window_size, prepare_config_file_for_editing
|
||||||
|
)
|
||||||
|
from .constants import appname, editor, set_boss
|
||||||
from .fast_data_types import (
|
from .fast_data_types import (
|
||||||
ChildMonitor, create_os_window, current_os_window, destroy_global_data,
|
ChildMonitor, create_os_window, current_os_window, destroy_global_data,
|
||||||
destroy_sprite_map, get_clipboard_string, glfw_post_empty_event,
|
destroy_sprite_map, get_clipboard_string, glfw_post_empty_event,
|
||||||
@ -410,6 +412,11 @@ class Boss:
|
|||||||
SpecialWindow(
|
SpecialWindow(
|
||||||
self.opts.scrollback_pager, data, _('History'), overlay_for=window.id))
|
self.opts.scrollback_pager, data, _('History'), overlay_for=window.id))
|
||||||
|
|
||||||
|
def edit_config_file(self, *a):
|
||||||
|
confpath = prepare_config_file_for_editing()
|
||||||
|
cmd = editor + [confpath]
|
||||||
|
self.new_os_window(*cmd)
|
||||||
|
|
||||||
def input_unicode_character(self):
|
def input_unicode_character(self):
|
||||||
w = self.active_window
|
w = self.active_window
|
||||||
tab = self.active_tab
|
tab = self.active_tab
|
||||||
|
|||||||
@ -59,11 +59,35 @@ find_app_name(void) {
|
|||||||
return @"kitty";
|
return @"kitty";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface GlobalMenuTarget : NSObject
|
||||||
|
+ (GlobalMenuTarget *) shared_instance;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation GlobalMenuTarget
|
||||||
|
|
||||||
|
- (void) show_preferences : (id)sender {
|
||||||
|
(void)sender;
|
||||||
|
call_boss(edit_config_file, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (GlobalMenuTarget *) shared_instance
|
||||||
|
{
|
||||||
|
static GlobalMenuTarget *sharedGlobalMenuTarget = nil;
|
||||||
|
@synchronized(self)
|
||||||
|
{
|
||||||
|
if (!sharedGlobalMenuTarget)
|
||||||
|
sharedGlobalMenuTarget = [[GlobalMenuTarget alloc] init];
|
||||||
|
return sharedGlobalMenuTarget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
void
|
void
|
||||||
cocoa_create_global_menu(void) {
|
cocoa_create_global_menu(void) {
|
||||||
NSString* app_name = find_app_name();
|
NSString* app_name = find_app_name();
|
||||||
NSMenu* bar = [[NSMenu alloc] init];
|
NSMenu* bar = [[NSMenu alloc] init];
|
||||||
|
GlobalMenuTarget *global_menu_target = [GlobalMenuTarget shared_instance];
|
||||||
[NSApp setMainMenu:bar];
|
[NSApp setMainMenu:bar];
|
||||||
|
|
||||||
NSMenuItem* appMenuItem =
|
NSMenuItem* appMenuItem =
|
||||||
@ -75,6 +99,9 @@ cocoa_create_global_menu(void) {
|
|||||||
action:@selector(orderFrontStandardAboutPanel:)
|
action:@selector(orderFrontStandardAboutPanel:)
|
||||||
keyEquivalent:@""];
|
keyEquivalent:@""];
|
||||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
NSMenuItem* preferences_menu_item = [[NSMenuItem alloc] initWithTitle:@"Preferences..." action:@selector(show_preferences:) keyEquivalent:@","];
|
||||||
|
[preferences_menu_item setTarget:global_menu_target];
|
||||||
|
[appMenu addItem:preferences_menu_item];
|
||||||
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", app_name]
|
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", app_name]
|
||||||
action:@selector(hide:)
|
action:@selector(hide:)
|
||||||
keyEquivalent:@"h"];
|
keyEquivalent:@"h"];
|
||||||
@ -124,7 +151,7 @@ cocoa_create_global_menu(void) {
|
|||||||
setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
|
setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
|
||||||
[NSApp setWindowsMenu:windowMenu];
|
[NSApp setWindowsMenu:windowMenu];
|
||||||
[windowMenu release];
|
[windowMenu release];
|
||||||
|
[preferences_menu_item release];
|
||||||
|
|
||||||
[bar release];
|
[bar release];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -478,8 +478,7 @@ def commented_out_default_config():
|
|||||||
|
|
||||||
|
|
||||||
def prepare_config_file_for_editing():
|
def prepare_config_file_for_editing():
|
||||||
if os.path.exists(defconf):
|
if not os.path.exists(defconf):
|
||||||
return
|
|
||||||
d = os.path.dirname(defconf)
|
d = os.path.dirname(defconf)
|
||||||
try:
|
try:
|
||||||
os.makedirs(d)
|
os.makedirs(d)
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ str_version = '.'.join(map(str, version))
|
|||||||
_plat = sys.platform.lower()
|
_plat = sys.platform.lower()
|
||||||
is_macos = 'darwin' in _plat
|
is_macos = 'darwin' in _plat
|
||||||
base = os.path.dirname(os.path.abspath(__file__))
|
base = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
editor = shlex.split(os.environ.get('EDITOR', 'vim'))
|
||||||
|
|
||||||
|
|
||||||
ScreenGeometry = namedtuple('ScreenGeometry', 'xstart ystart xnum ynum dx dy')
|
ScreenGeometry = namedtuple('ScreenGeometry', 'xstart ystart xnum ynum dx dy')
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#
|
#
|
||||||
# You can get a list of full family names available on your computer by running
|
# You can get a list of full family names available on your computer by running
|
||||||
# kitty list-fonts
|
# kitty list-fonts
|
||||||
|
# The default values shown below rely on your OS to choose an appropriate monospace font family.
|
||||||
font_family monospace
|
font_family monospace
|
||||||
italic_font auto
|
italic_font auto
|
||||||
bold_font auto
|
bold_font auto
|
||||||
@ -341,6 +342,7 @@ map ctrl+shift+minus decrease_font_size
|
|||||||
map ctrl+shift+backspace restore_font_size
|
map ctrl+shift+backspace restore_font_size
|
||||||
map ctrl+shift+f11 toggle_fullscreen
|
map ctrl+shift+f11 toggle_fullscreen
|
||||||
map ctrl+shift+u input_unicode_character
|
map ctrl+shift+u input_unicode_character
|
||||||
|
map ctrl+shift+f2 edit_config_file
|
||||||
# Open a currently visible URL using the keyboard. The program used ot open the URL is specified in open_url_with.
|
# Open a currently visible URL using the keyboard. The program used ot open the URL is specified in open_url_with.
|
||||||
# You can customize how the URLs are detected and opened by specifying command line options to
|
# You can customize how the URLs are detected and opened by specifying command line options to
|
||||||
# url_hints. For example:
|
# url_hints. For example:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user