6

Say my present working directory is /home/abc/documents/xyz. Now in tmux, when I split my screen, the new pane defaults to the /home/abc directory. I want the pwd to be retained upon splitting.

1
  • 2
    Similair question on unix.exchange, describes how to open new window while retaining the current pwd
    – bbaja42
    Jun 25, 2011 at 21:24

3 Answers 3

1

You can put something like the following in your tmux.conf file:

bind <key of your choice> default-path $(pwd) \; split-window\; set default-path ~/

This binds to the chosen or a command which changes the default path for new panes to the current directory of the current pane (via the output of pwd) and then splits the pane, and then binds it back to home.

I read this trick on ArchWiki a while back. There's another more in-depth method that uses cd if you follow the link, though it has its own issues so I'd personally recommend sticking with what's shown above.

3
  • The tip you linked to works when it is executed from a shell command line because the shell expands the $() command substitution. However, this same command cannot actually “be easily bound to a key” because tmux does not do command substitution for the value given to set default-path (even if it did, the effective cwd would be that of the server, not that of the foreground process of the active pane). Dec 9, 2011 at 6:17
  • Also, there really is no need to even mess with default-path for the case of creating a pane/window with the same cwd as an existing shell because tmux split-window/tmux new-window from (e.g.) a shell will pass its cwd (inherited from its parent, (e.g.) the shell) to the process started for the new pane. Dec 9, 2011 at 6:42
  • A note since I'm not allowed to make that small of an edit: the first default-path above should be set default-path.
    – Henrik N
    Feb 28, 2012 at 22:14
6

The default-path described on a previous answer is no longer a compatible, this behavior was changed from tmux 1.8 to tmux 1.9.

The way to do this now is to have binds that do neww -c '#{pane_current_path}' or the same with split-window.

Please refer to the changes exposed here: https://github.com/tmux/tmux/blob/master/CHANGES , in the section that reads CHANGES FROM 1.8 to 1.9, 20 February 2014.

0
1

theres a zsh-plugin for that https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/last-working-dir/last-working-dir.plugin.zsh

coincidentally I have this behaviour via a ssh:ed session but I don't know what setting this is.

1
  • This solution has a bit of a lag to it, but works and is the easiest method given you use oh-my-zsh. May 7, 2023 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .