From 3778ae40055e239222b8ab4856e1ea485252ae73 Mon Sep 17 00:00:00 2001 From: Justas Kazakauskas Date: Sat, 8 Oct 2022 15:40:56 +0300 Subject: [PATCH] Add kitty terminal support --- README.md | 14 ++++++++++++++ code_sender/kitty/__init__.py | 7 +++++++ code_sender/sender.py | 7 +++++++ 3 files changed, 28 insertions(+) create mode 100644 code_sender/kitty/__init__.py diff --git a/README.md b/README.md index 13c6de6..247aebe 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,20 @@ There are two main keybindings: Most likely you haven't enabled JavaScript for AppleScript. Check the option "Allow JavaScript from Apple Events" in the `Develop` menu (the `Develope` menu needs to be enabled in the preferences). +1. Kitty + All text commands from Sublime Text to Kitty are sent through the unix socket, so it is vital to have correct configuration on both sides. Please follow these steps: + + 1. Add this configuration to your `SendCode.sublime-settings`: + ```json + "prog": "kitty", + "kitty": { + "path": "/path/to/kitty", + "socket": "unix:/tmp/kitty", + } + ``` + 2. Add `allow_remote_control socket-only` to your `kitty.conf` + 3. Start kitty with `--listen-on=unix:/tmp/kitty` flag. If you are using MacOS you can conveniently put it into `/macos-launch-services-cmdline` file. + 4. Double check that `echo $KITTY_LISTEN_ON` is pointing to the same socket as defined in your Sublime Text configuration. ### Custom Keybindings diff --git a/code_sender/kitty/__init__.py b/code_sender/kitty/__init__.py new file mode 100644 index 0000000..5055536 --- /dev/null +++ b/code_sender/kitty/__init__.py @@ -0,0 +1,7 @@ +from os import system +from shlex import quote + +def send_to_kitty(cmd, path, socket): + template = "{path} @ --to {socket} send-text --match state:focused {cmd}\r" + command = template.format(path=path, socket=socket, cmd=quote(cmd)) + system(command) diff --git a/code_sender/sender.py b/code_sender/sender.py index 102d344..a7a17a6 100644 --- a/code_sender/sender.py +++ b/code_sender/sender.py @@ -15,6 +15,7 @@ from .safari import send_to_safari_jupyter, send_to_safari_rstudio from .sublimerepl import send_to_sublimerepl from .terminus import send_to_terminus +from .kitty import send_to_kitty from .clipboard import clipboard @@ -86,6 +87,10 @@ def send_to_rstudio(self, cmd): else: send_to_rstudio(cmd) + def send_to_kitty(self, cmd): + kitty = self.settings.get("kitty", "kitty") + send_to_kitty(cmd, kitty["path"], kitty["socket"]) + def send_text(self, cmd): cmd = cmd.rstrip() cmd = cmd.expandtabs(self.view.settings().get("tab_size", 4)) @@ -116,6 +121,8 @@ def send_text(self, cmd): self.send_to_terminus(cmd) elif prog == "rstudio": self.send_to_rstudio(cmd) + elif prog == "kitty": + self.send_to_kitty(cmd) else: sublime.message_dialog("%s is not supported for current syntax." % prog)