This small snippet of code allows opening windows/panes inside tmux in the same UNIX directory.
When working on project I quite often want to open new window or pane in Tmux in the same directory where I am now at the moment. Before I figured out how to do it, it was like this: open new pane,
cd <...>. Even with single
cd and tab completion, navigating through deeply nested project tree can be not that easy.
Here's the small shell function and alias to help.
This is how I use it
When I want new window or pane to be created and
cd to that dir automatically I simply type
pwd and after this open new window/pane.
And this is how it works
tmux_pwdfunction executed in your current directory simply sets option for window in your current Tmux session to use this directory as default (lines 3 and 4 of the gist).
- Line 3 detects current session of the tmux.
- I don't want this function to be executed in the shell which does not run under Tmux. Hence the line No 1 in gist.
- And I don't want all my new windows to be opened in this directory forever. I have my 'global' default directory, which is
~/Development, and this is where all my windows usually open. So, there's a 'timeout' setting to set my default directory back after 5 mins. Lines 5 and 6.
- And finally there's an alias, on line 8.
I've added this to my zsh functions, but I don't see why it shouldn't work in another shells like Bash.