Code Monkey home page Code Monkey logo

Comments (18)

sukima avatar sukima commented on July 20, 2024 3

The solution is simple, nest TMUX inside TMate. Unfortunately the information above on how to do this seem rather complicated. Here is my take to add to the confusion and maybe it will help someone.

First understand your TMUX prefix key. By default this is CTRL-B In the following examples I have choosen to use CTRL-Space by use of this command in my .tmux.conf file:

set-option -g prefix C-Space

Next in your .tmate.conf file you have to change this. I choose CTRL-y in these examples. First unbind the prefix you set in .tmux.conf and redefine the prefix in .tmate.conf To make things even better I've taken the extra step of unbinding keys that I want to pass directly through to TMUX and turning the status off (as nesting would normally produce two status bars). Here is my full .tmate.conf file:

unbind-key C-Space
set-option -g prefix C-y
bind-key C-y send-prefix
unbind -n C-h
unbind -n C-j
unbind -n C-k
unbind -n C-l
set-option -g status off

Lastly, when I launch I do so in two steps. Since I live in TMUX normally I typically will detach and reattach inside tmate when I need. Alternatively I could also launch a new session inside tmate if I wish. The trick is when inside tmate to always prefix my TMUX commands with TMUX=. Here is an example:

$ tmate
------------------- Inside tmate ---------------------
$ TMUX= tmux attach

from tmate.

nviennot avatar nviennot commented on July 20, 2024 3

This should be easy to do once tmate decouples itself from tmux (a regular tmux attach inside a tmate session will be sufficient). Thank you @sukima for providing some guidance around this issue.

from tmate.

nviennot avatar nviennot commented on July 20, 2024 2

I don't see how to share an existing tmux session properly :/
Any ideas?

from tmate.

nviennot avatar nviennot commented on July 20, 2024 1

Before proposing paid offerings, which will most likely be used for production environment, I need to do a bit of work. I need to restructure the whole server-side, to allow reconnections, and fault tolerance (if one of my server dies). The new pipeline will also allow incorporation of websockets (for the HTML5 stuff), and session recording (probably to Cassandra, with fulltext search done with Elasticsearch).
Not to worry, the free pairing feature will never go away.

Thanks for the support :)

from tmate.

nviennot avatar nviennot commented on July 20, 2024

This is not possible.
What you could do instead is always run tmate.

from tmate.

stefanpenner avatar stefanpenner commented on July 20, 2024

@nviennot i've thought about this, but it appears tmate ls does not make it easy for my to re-attach to my existing local tmate sessions

from tmate.

nviennot avatar nviennot commented on July 20, 2024

I see.

I guess I'll have to implement multi sessions to make it work :)

from tmate.

mikedfunk avatar mikedfunk commented on July 20, 2024

multiple sessions would be nice

from tmate.

nviennot avatar nviennot commented on July 20, 2024

I have some paper deadline to deal with at the moment, I will give tmate some love soon.

from tmate.

jmgarnier avatar jmgarnier commented on July 20, 2024

This feature would be awesome 😸

This is exactly the kind of the feature I am willing to pay a yearly subscription for!

from tmate.

nviennot avatar nviennot commented on July 20, 2024

My paper deadline is in two weeks, so I'll give it some thoughts fairly soon :)

from tmate.

sighmin avatar sighmin commented on July 20, 2024

Yeah I'd also pay for it.

I always run tmate but then the session times out from time to time then have to close tmate and recreate it which is a bit annoying - would be cool to be able to grab a new session at tmate.io ?

You're doing a great job dude!

from tmate.

maljub01 avatar maljub01 commented on July 20, 2024

You can nest tmux & tmate sessions as much as you like as long as you first set TMUX to an empty value.

So inside an existing tmux/tmate session, you can run new ones like this:

TMUX='' tmate
TMUX='' tmux

You can also access pre-existing tmux sessions on the machine you're accessing using tmate by using:

TMUX='' tmux list-sessions
TMUX='' tmux attach-session -t SESSION_NAME

You'll need to be careful though because the tmux prefix will always be captured by the outer tmux/tmate session, and you'll need to press it twice to have tmux forward it one level deeper. This means you'll need to press it 2 ^ depth times in order to reach inner sessions (assuming depth starts at 0).

Basically, when you press Ctrl-B once, you'll be sending commands to the outermost session, pressing it twice will send commands to the one inside it, and to access a session inside that one, you'll need to press it 4 times.

Having to press Ctrl-B Ctrl-B Ctrl-B Ctrl-B Ctrl-N to move between windows is either totally crazy or totally awesome. 😜

However, if you manage your tmux sessions properly you will never need more than 2 levels (ie. max depth = 1).

One way to do this would be to:

  1. Have your main work done in a tmux session.
  2. Whenever you need to add a new person, create a tmate session in a different terminal and have them join it and from there attach to your original tmux session.
  3. You can even setup tmate to use a different prefix so it will stay out of your way while you're using the shared tmux session.
  4. Profit!

I have a few words of advice though:

  1. Make sure you can reattach to your nested tmate sessions if you accidentally detach from them by pressing too few or too many Ctrl-B's. #31 should help you avoid locking yourself out.
  2. Make sure you don't get an infinite recursion of tmux/tmate sessions (ie. attach to a tmux session from within itself). If you do, just use the appropriate combination of Ctrl-B's followed by a Ctrl-D (to detach from the offending session), and then wait a few seconds until tmux sorts the craziness out and returns to normal.

This works for me, and it works pretty well actually. But I cannot guarantee that it will not blow up in your face, so be careful. 👍

from tmate.

taylor avatar taylor commented on July 20, 2024

Until attach/detach work with tmate I recommend nesting tmux as mentioned by @maljub01. To deal with the nested command key I suggest setting tmate to something other than what is used by tmux. I can recommend using ctrl-] which is telnet's escape sequence.

Basically treat tmate as a sharing container for whatever work you are doing and not for any of it's tmux capabilities.

from tmate.

sukima avatar sukima commented on July 20, 2024

I to find this solution better, Mainly because tmux is at version 1.9 and when I run tmate I loose many features in the tmux binary that tmate doesn't have.

from tmate.

juandazapata avatar juandazapata commented on July 20, 2024

Ping

from tmate.

jaspervanbrian avatar jaspervanbrian commented on July 20, 2024

Hello, I just implemented a solution but it is quite different. I set up my ~/.bashrc/~/.zshrc to open tmux initially. Here is my initial setup:

        # Launch TMUX
	# If not running interactively, do not do anything
	[[ $- != *i* ]] && return
	[[ -z "$TMUX" ]] && exec tmux
	tmux_count=$(tmux list-panes | wc -l)
	if [[ $tmux_count == 1 ]] ; then
	#	neofetch
		((tmux_count++))
	fi

Now I installed tmate, but I also wanted to execute tmate inside a tmux pane. Here's what I did:

# Check if user has opened tmate
if [[ -z "$ZSH_TMATE" ]]
then
	# Launch TMUX
	# If not running interactively, do not do anything
	[[ $- != *i* ]] && return
	[[ -z "$TMUX" ]] && exec tmux
	tmux_count=$(tmux list-panes | wc -l)
	if [[ $tmux_count == 1 ]] ; then
	#	neofetch
		((tmux_count++))
	fi

	# Alias tmate
	export ZSH_TMATE=tmate
	alias tmate="gnome-terminal"
else
	unset TMUX
	unset ZSH_TMATE
	exec tmate
fi

First, it checks if a ZSH_TMATE variable has been set. If no variable is detected, I will set the variable and will alias the tmate command to open a new gnome-terminal instance.

It will open a new gnome-terminal, and on the gnome-terminal instance, it will check if a ZSH_TMATE variable is set. It will pass on the else case because you have set it earlier.

I needed to unset the ZSH_TMATE variable, because it causes an infinite loop that nests a tmate instance with another tmate instance. Not exactly sure why it happens tho, I just experimented it a little.

Working demo:

ezgif com-video-to-gif

from tmate.

laudai avatar laudai commented on July 20, 2024

@sukima thanks you for propose this way. It look likes tmux in tmux or tmux in tmate, your need force reset the $TMUX variable to run nested tmux session !

from tmate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.