Tmux Part 5: Advanced Workflow

Advanced Workflow Quick Panes As quick as we've been able to make it to open a pane and interact with a process, it turns out that tmux accepts an optional shell-command argument to the split-window command that can make this even more efficient...
This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/tmux-advanced-workflow

Hi,

Really good stuff here. Iā€™m adding ā€œquick paneā€ to my configuration to open a tail of my application log file. This gets the job done:

bind-key l split-window -h -c '#{pane_current_path}' "tail -f  log/development.log" 

However, ideally, Iā€™d like the new paneā€™s starting path to be the original path of the originating pane. There is such a variable mentioned in the tmux man page:

pane_start_path                 Path pane started with

Problem is pand_start_path seems to be empty. I found this issue on the tmux sourceforge page that appears to be someoneā€™s attempt to fix this, but it doesnā€™t look like that patch was ever merged and the thread just dead ends.

Iā€™m wondering if perhaps I am (and the original poster on the sourcforge thread linked above) are just misinterpreting the purpose of pane_start_path. Furthermore (and most importantly), Iā€™m curious if anyone has any alternative ideas for setting up a quick pane shortcut that is based off of the originating paneā€™s original path.

Thanks, really enjoying the content here!

Hello @jzw, thanks for the kind words. As to your question, when you say the ā€œoriginal path of the originating paneā€ do you mean the path that the session started in, or the start path of the current pane?

@christoomey thatā€™s a good point. I would like the new pane to be relative to the path that the session started in. So using pane_start_path was not what I was looking for even if were not blank.

If you want the pane to inherit the path that the session started at, you should be able to leave off the -c flag and just use the default behavior.

Great tutorial @christoomey!! really loving tmux and working again with vim!!

Was wondering maybe you could share how you use the todo list and the wiki in your normal working day? I have a good idea how a todo are used (they are a pretty simple idea :blush: ) but i guess what Iā€™m really asking is if there is a good vim plugin to manage your todos.

Would love to know how you use wikis?

Thanks, Hass

Hey @hass_isnull, glad to hear youā€™re enjoying the tutorial!

My use of both todo lists and wikis tends to be random and might not be the best guide, but I can share some high level thoughts.

Speed is the most important thing to me. I want to be able to get an idea out of my head and into my todo list or wiki as quickly as possible, and preferably without losing context. Thus the use of the tmux quick pane functionality I demoed.

My todo list is a simple text file formatted as markdown using markdown headings and lists to build up a small hierarchy. Nothing too fancy. Similarly, my wiki is just a directory of markdown files stored in dropbox. Iā€™ve explored various enhancements with linking and other fancy things, but mostly now just focus on quick access and regular review.

If youā€™re looking for more structure / vim integration, Iā€™d recommend taking a look at any of the following:

Hope that helps!

Great video!

If anyone is having issues with ensure_tmux_is_running, make sure you are defining these shell functions after you have exported your path settings. Otherwise tat wonā€™t be available when you try to call it.

Iā€™m getting these errors when restarting bash: Hunts-MBP:~ rhnorment$ source ~/.bashrc
-bash: /Users/rhnorment/.bashrc: line 3: syntax error near unexpected token }' -bash: /Users/rhnorment/.bashrc: line 3: _not_inside_tmux() { [[ -z ā€œ$TMUXā€ ]] }ā€™

Any ideas?

Hi @rhnorment. I just tested in bash and it seems to work fine. Can you paste the full section of lines from your bashrc?

Here you go!

export EDITOR="/usr/local/bin/mate -w"

_not_inside_tmux() { [[ -z "$TMUX" ]] }

ensure_tmux_is_running() {
  if _not_inside_tmux; then
    tat
  fi
}

ensure_tmux_is_running

@rhnorment I edited your post slightly to mark that region as code (using backtick code block). Unfortunately Iā€™m not seeing anything. Can you try copying and pasting line 3 into your shell directly to see if that also fails?

Same error, Chris: -bash: syntax error near unexpected token `}ā€™

Itā€™s no biggie. I like the script though. Thanks for all you guys do.

@christoomey Thanks for another great video. Early on (about 1:20), you hit C-d to close a pane. Iā€™ve searched through the tmux documentation and the config that you create, and I canā€™t find where that key binding comes from and what exactly it does. Can you shed some light on that?

Hello @ticsucty, assuming you are referring to the point where I close the pane in which I had been running htop (right around 1:20 as you said), then this is not any special configuration, this is just the default tmux behavior.

Panes will close when the base process running in the them closes. Typically this will be your shell, and C-d at your shell prompt (and just about every other interactive prompt as well) will close it.

You can test this yourself by running

  • <prefix>% to open a new split
  • C-d to kill the shell process, and tmux will close the pane.

Later in the video I discuss how to start panes with a particular command, for instance vim, and with that workflow the pane will close when Vim closes.

@christoomey Great vid as always.

Where can I gain access to the VIM command, CTRL+P? Referenced at 3:43 in the video.

Just so happens we have video in our Vim course with a segment on CtrlP ;).

Yay, I knew it was there somewhere, just havenā€™t gotten to it!

Hey @christoomey , Iā€™m having the exact same issue as @rhnorment putting this in my ~/.bashrc. When I launch urxvt I get bash: /home/user/.bashrc: line 25: syntax error near unexpected token }' bash: /home/user/.bashrc: line 25: _not_inside_tmux() { [[ -z ā€œ$TMUXā€ ]] }ā€™

The relevant lines:

# auto attach tmux session when shell is opened
_not_inside_tmux() { [[ -z "$TMUX" ]] }

ensure_tmux_is_running() {
  if _not_inside_tmux; then
    tat
  fi
}

ensure_tmux_is_running

Iā€™m new here, thanks for the awesome content!

Seems like bash didnā€™t like the one line function. I just split _not_inside_tmux onto multiple lines

# auto attach tmux session when shell is opened
_not_inside_tmux() { 
  [[ -z "$TMUX" ]]
}

worked just fine

1 Like