Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix external tmux command without display #1605

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion alot/commands/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def __init__(self, cmd, stdin=None, shell=False, spawn=False,
logging.debug('calling hook: touch_external_cmdlist')
res = touchhook(cmd, shell=shell, spawn=spawn, thread=thread)
logging.debug('got: %s', res)
cmd, shell, self.in_thread = res
cmd, shell, thread = res
# otherwise if spawn requested and X11 is running
elif spawn:
if 'DISPLAY' in os.environ:
Expand All @@ -230,6 +230,7 @@ def __init__(self, cmd, stdin=None, shell=False, spawn=False,
termcmdlist = split_commandstring(term_cmd)
cmd = termcmdlist + cmd
else:
logging.warning('unable to handle spawn outside of X11 without touch_external_cmdlist hook set')
thread = False

self.cmdlist = cmd
Expand Down
12 changes: 12 additions & 0 deletions extra/hooks/external_command_tmux_without_x11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os


def touch_external_cmdlist(cmd, shell=False, spawn=False, thread=False):
# Used to handle the case where tmux isn't running within X11
if spawn and 'TMUX' in os.environ:
termcmdlist = ['tmux-horizontal-split-blocking.sh']
cmd = termcmdlist + cmd
# Required to avoid tmux trying to nest itself.
shell = False

return cmd, shell, thread
17 changes: 17 additions & 0 deletions extra/tmux-horizontal-split-blocking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# Uses unique tmux wait-for channel based on time with nanoseconds
# Inspired by cjpbirkbeck's example @ https://github.com/pazz/alot/issues/1560#issuecomment-907222165

IFS=' '

# Ensure we're actually running inside tmux:
if [ -n "$TMUX" ]; then
fin=$(date +%s%N)
# Use new-window to create a new window instead.
tmux split-window -h "${*}; tmux wait-for -S ${fin}"
tmux wait-for "${fin}"
else
# You can replace xterm with your preferred terminal emulator.
xterm -e "${*}"
fi