Tmux Tips – How to Change Default New Window Directory

gnu-screenlinuxtmux

I recently moved from GNU screen to tmux.
I find it quite similar but with bigger support (I switched due to problem with escape-time in neovim– resolution was only for tmux).

Unfortunately in tmux I'm unable to find a similar command to this:

screen -X eval "chdir $(some_dir)"

The command above changed the default directory for new window/screen/pane from within the GNU screen so when I pressed Ctrl+a (similar to tmux Ctrl+b)- new window opened in the $(some_dir) directory.

Is there a similar thing in tmux?

ANSWER:
I have used @Lqueryvg answer and combined it with @Vincent Nivoliers suggestion froma a comment and that gave me a new binding for a command attach -c "#{pane_current_path}" which sets my current directory as a default one.
Thanks.

Best Answer

  1. Start tmux as follows:

    (cd /aaa/bbb; tmux)
    

    Now, any new windows (or panes) you create will start in directory /aaa/bbb, regardless of the current directory of the current pane.

  2. If you want to change the default directory once tmux is up and running, use attach-session with -c.

    Quoting from the tmux man page for attach-session:

    -c will set the session working directory (used for new windows)
    to working-directory.
    

    For example:

    • Ctrl+b :

    • attach -c /ddd/eee

    New windows (or panes) will now start in directory /ddd/eee, regardless of the directory of the current pane.

Related Question