Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ Project-wise settings could also be specified in `sublime-project` as
}
```

#### Enabling selection by window name/title (WM_NAME) for linux-terminal

If you have multiple instances of the same terminal emulator running (e.g. one `alacritty` window for R, one for IPython, etc.), you may want to want to send code to a terminal with a specific name/title (e.g. so `python` code is sent to the window named `My Special IPython` but 'julia' code is sent to `My Julia`). If you force a permanent window name when running your terminal emulator (e.g. `$ alacritty -t "My Special IPython"`), you can place this name in a `window_name` SendCode setting. SendCode will then first try to find a window with the corresponding `WM_NAME` *before* using the `WM_CLASS` specified by the `linux_terminal` global setting.

It is not recommended to use the `window_name` setting unless you specify a permanent window name when running your terminal emulator; by default, window names may change frequently, making this setting useless. Note that `window_name` is only meaningful when in a settings block where `prog` is set to `linux-terminal`.
Comment thread
cdbrendel marked this conversation as resolved.
Outdated

### Block expansion

Expand Down
29 changes: 23 additions & 6 deletions code_sender/linux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
import time
import os
from ..clipboard import clipboard
from subprocess import CalledProcessError

plat = sublime.platform()

if plat == "linux":
from ..xdotool import xdotool

def send_to_linux_terminal(linux_terminal, cmd_list):
wid = xdotool("search", "--onlyvisible", "--class", linux_terminal)
if not wid:
raise Exception("{} not found.".format(linux_terminal))

wid = wid.decode("utf-8").strip().split("\n")[-1]
def send_to_linux_terminal(wids, cmd_list):
wid = wids.decode("utf-8").strip().split("\n")[-1]

if isinstance(cmd_list, str):
cmd_list = [cmd_list]
Expand Down Expand Up @@ -42,7 +39,27 @@ def send_to_linux_terminal(linux_terminal, cmd_list):
else:
xdotool("windowfocus", sublime_id)

def get_linux_wids(window_name, linux_terminal):
try:
wids = xdotool("search", "--onlyvisible", "--name", window_name)
return wids
except CalledProcessError:
sublime.status_message("{} (WM_NAME) not found; trying {} (WM_CLASS)"
.format(window_name, linux_terminal))
except TypeError:
# We get here if window_name is None, meaning we should just look at WM_CLASS
pass

wids = xdotool("search", "--onlyvisible", "--class", linux_terminal)

if not wids:
raise Exception("{} not found.".format(linux_terminal))

return wids

else:
def send_to_linux_terminal(cmd):
pass

def get_linux_wids(cmd):
pass
14 changes: 9 additions & 5 deletions code_sender/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .r import send_to_r
from .rstudio import send_to_rstudio
from .conemu import send_to_conemu, send_to_cmder
from .linux import send_to_linux_terminal
from .linux import send_to_linux_terminal, get_linux_wids
from .tmux import send_to_tmux
from .screen import send_to_screen
from .chrome import send_to_chrome_jupyter, send_to_chrome_rstudio
Expand Down Expand Up @@ -57,8 +57,10 @@ def send_to_cmder(self, cmd):
send_to_cmder(cmd, conemuc, bracketed=self.bracketed_paste_mode)

def send_to_linux_terminal(self, cmd):
window_name = self.settings.get("window_name")
linux_terminal = self.settings.get("linux_terminal")
send_to_linux_terminal(linux_terminal, cmd)
wids = get_linux_wids(window_name, linux_terminal)
send_to_linux_terminal(wids, cmd)

def send_to_tmux(self, cmd):
tmux = self.settings.get("tmux", "tmux")
Expand Down Expand Up @@ -225,15 +227,17 @@ def send_to_cmder(self, cmd):
send_to_cmder(cmd, conemuc)

def send_to_linux_terminal(self, cmd):
window_name = self.settings.get("window_name")
linux_terminal = self.settings.get("linux_terminal")
wids = get_linux_wids(window_name, linux_terminal)

if len(re.findall("\n", cmd)) > 0:
if self.bracketed_paste_mode:
send_to_linux_terminal(linux_terminal, [cmd, ""])
send_to_linux_terminal(wids, [cmd, ""])
Comment thread
cdbrendel marked this conversation as resolved.
Outdated
else:
send_to_linux_terminal(linux_terminal, [r"%cpaste -q", cmd, "--"])
send_to_linux_terminal(wids, [r"%cpaste -q", cmd, "--"])
else:
send_to_linux_terminal(linux_terminal, cmd)
send_to_linux_terminal(wids, cmd)

def send_to_tmux(self, cmd):
tmux = self.settings.get("tmux", "tmux")
Expand Down