Intro

In line with my use of Vim and Tmux, and specifically a fork of the latter which I frequently use for pairing, Tmate, I encountered an issue that began to hinder my productivity when pairing.

Tmate is a fork of Tmux, so we get the terminal multiplexer characteristics of Tmux with Tmate. Tmux provides a session. Tmate provides the ssh connectivity.

Tmate is a great tool that allows us to share Tmux sessions with collaborators through a generated ssh key. Once inside the session, our collaborator can at least see all that we are doing from within the terminal. We can open new panes, open vim sessions, you get the picture.

The trouble is, if for whatever reason we lose connectivity to the Tmate session, we lose the entire set-up, or the work environment that we were working with. In another scenario, if either myself or the pairing partner decide to call it a day, we won’t be able to pick things back up from where we left off the next day. We will have to set-up the whole environment all over again. Which could be a nuissance, especially if you’re dealing with multiple projects at the same time and don’t want to have to go through this hassle.

Initially, I was told to look into DVTM as option since it allows both session management and is a terminal multiplexer, but is more for Linux than it is for macOS. Since I’m using a mac there was little documentation that explained how to go about doing this. So we had to be slightly more resourceful.

Using dtach instead of DVTM

There’s very little difference between abduco and dtach in terms of functionality.

What’s the difference between both of those?

Tmux has session and window/pane management, abduco and dtach are session managers only dvtm is a terminal that has multiple panes, and so is the other half of what Tmux does.

So I was previously using Tmux (and Tmate) for the session management, the latter to connect to temporary ssh sessions. the problem was that I could not reconnect to previous sessions - I had to basically remember the previous set-ups I was working with when pair programming.

In order to avoid this hindrance of: “once we close a session, we lose access to previous layouts”, we can use can use dtach to “rememeber” the layout structure of “sessions” or a layout that we may use recurrently.

The new workflow I am using is:

So dtach recognises that it’s job is to remember a session layout, and now does the session management software. Tmux gives us the session side and the terminal splitting functionality.

The only issue encountered was the dtach command required to set up a session, but by using aliases in the .zshrc file in our root, we can fix this slight issue.


Out of the box commands

FROM THE MANUAL

EXAMPLES The following example creates a new session that has the detach character and suspend processing disabled. A socket is created in the /tmp directory for the session.

      $ dtach -c /tmp/foozle -Ez bash

   The following example attaches to the /tmp/foozle session if it

exists, and if not, creates a new session using /tmp/foozle as the socket for the session. Processing of the suspend character is also disabled for the attach instance.

      $ dtach -A /tmp/foozle -z bash

   The following example attaches to the /tmp/foozle session, using

the winch redraw method to redraw the screen.

      $ dtach -a /tmp/foozle -r winch

   The following example creates a new session and sets the default

redraw method for the session to the winch redraw method.

      $ dtach -c /tmp/foozle -r winch bash

To find the manual, just do man dtach to get up the manual in the terminal.

Making Aliases

Instead of having to use these commands to set up our sessions, we can include the following in our .zshrc config file:

 # Tmux command for loading the configurations of Tmux into Tmate when creating new ssh session
 alias tmate='tmate -f ~/.tmux.conf'<1>

 alias dt='ls -1 ~/.local/dtach/sessions/'

 dta() {
   dtach -a ~/.local/dtach/sessions/$1
 }

 dtc() {
   dtach -n  ~/.local/dtach/sessions/$1 $2 $3 $4 $5
 }

<1> I’ve included the alias that I set for loading Tmate, which essentially loads all the configurations and alternative binding keys I customised for my personal use.

Having the above configurations now allows us to use the following commands for dtach to get what we need:

`dt` #=> Shows the list of dtach sessions open 

`dtc [name_of_session_to_create] [command to do]`

# For Example:

`dtc VIM vim . `

`dta VIM` #=> Will open that session here

`control + \` #=> Close the session, but we can open it again at any time, provided we do not 'exit' it.