greymd / tmux-xpanes

Awesome tmux-based terminal divider
MIT License
1.96k stars 61 forks source link

Detach and re-attach + Use Case #168

Closed mossmoss closed 3 years ago

mossmoss commented 3 years ago

Thanks for this software. I had been using a tmux + ssh-multi.sh script - but saw this project mentioned in the comments there and am now using tmux-xpanes.

I'm running tmux 3.0a / xpanes 4.1.3 ​in WSL2 (Ubuntu 20.04.2 LTS) on Windows 10 (as well as on OSX 10.15.7) and wondering how to detach and reattach xpanes sessions.

I usually use bind key + d to detach and tmux ls (to get session id or number) - then tmux a -t session-id

I'm able to reattach to an xpanes session using: tmux -S /home/user/.cache/xpanes/socket.1234 attach

Is this the only way to reattach to a detached xpanes/tmux session? Is there some way to have the session show with tmux ls?

Is there a way to name sessions to something other than a socket.id?

So far, I am only using a tmux-xpanes command like:

xpanes -c "ssh moss@{}" www1 www2 www3 www4

I'm using it in conjunction with ./ssh/config entries like this:

Host www1
hostname www1.xyz.com
User moss
  ProxyCommand=nc -X 5 -x localhost:1234 %h %p

and a socks/proxy connection via a bastion host running in a different tab - i.e.

ssh -D1234 moss@bas.xyz.com

greymd commented 3 years ago

Thank you for using tmux-xpanes. Can you set below alias in ~/.bashrc or other location of your shell and check if it meets your needs ?

alias xpanes='xpanes -S /tmp/tmux-$UID/default'

xpanes has -S option to explicitly specify the socket file.

Specifying the default path of tmux's socket file with this option, tmux ls to show not only running tmux's sessions but also sessions created by tmux-xpanes.

The path of tmux's socket file is /tmp/tmux-UID/default by default ( tmux/CHANGES).

$ alias xpanes='xpanes -S /tmp/tmux-$UID/default'
$ xpanes 1 2 3
[detached (from session xpanes-4721)]
$ tmux ls
4: 1 windows (created Sun Aug 22 19:41:39 2021) [362x80]
xpanes-4721: 1 windows (created Mon Aug 23 09:17:20 2021) [362x80]
mossmoss commented 3 years ago

Thanks!

This seems to be working but I have to type xpanes 1 2 3 vs. executing a script with this command in it. Executing the script, the alias fix doesn't work and I can't see the session with tmux ls.

I also hardcoded my UID into the alias because tmux-$UID might not have been working for me.