2

So I'm trying to update my .tmux.conf file to reflect the change for -c in new-window. I've added this to my conf and it's not working unfortunately. My new windows and panes always start in ~/:

# Saner splitting.
bind v split-window -c $PWD -h
bind s split-window -c $PWD -v

# Autorename sanely.
setw -g automatic-rename on

# Better name management
bind c new-window -c $PWD

My expected behavior is that my new pane or window will be in the directory of which ever pane I previously was in was. So If I'm in Window 1 that is in ~/Sites/project, my new window will also be there.

  • Try encapsulating $PWD in quotes like this: "$PWD" – phoops Apr 28 '14 at 20:39
4

You're using the wrong example. ;) Having $PWD as argument to -c means to have the newly created panes started in the directory the tmux server is in, in other words, the directory where you first started tmux. The directory of the current pane is the one stored in the tmux internal variable #{pane_current_path}:

* 'default-path' has been removed.  The new-window command accepts '-c' to
  cater for this.  The previous value of "." can be replaced with: 'neww -c
  $PWD', the previous value of '' which meant current path of the pane can
  be specified as:  'neww -c "#{pane_current_path}"'

So the right way to do what you want would be

# Saner splitting.
bind v split-window -c "#{pane_current_path}" -h
bind s split-window -c "#{pane_current_path}" -v

# Autorename sanely.
setw -g automatic-rename on

# Better name management
bind c new-window -c "#{pane_current_path}"

Note: This will not work if there's someone else's shell running in your current pane (I fell over this, so I explicitly tell you): If you've a running sudo or su session, you're new pane will end up with a working directory of /. This is quite simply to explain: your tmux cannot obtain the current working directory of the running process, since it hasn't the appropriate privileges to do so for security reasons (you cannot read vital state of a foreign user's process).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.