← Back to Upcase

Tmux Part 5: Advanced Workflow


(Upcase ) #1
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

(Zac Williams) #2

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!


(Chris Toomey) #3

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?


(Zac Williams) #4

@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.


(Chris Toomey) #5

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.


(Hassan Khalid) #6

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


(Chris Toomey) #7

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!


(Prescott Murphy) #8

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.


(Hunt Norment) #9

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?


(Chris Toomey) #10

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


(Hunt Norment) #11

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

(Chris Toomey) #12

@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?


(Hunt Norment) #13

Same error, Chris: -bash: syntax error near unexpected token `}’

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


(Marc Huffnagle) #14

@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?


(Chris Toomey) #15

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.


(thedanotto) #16

@christoomey Great vid as always.

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


(Chris Toomey) #17

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


(thedanotto) #18

Yay, I knew it was there somewhere, just haven’t gotten to it!


(Panashe Fundira) #19

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!


(Panashe Fundira) #20

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