When I create new window/pane in tmux, for example via tmux neww
or keybindings prefix+c
, prefix+%
etc, the new pane gets working directory the same as previous pane, but with dereferenced symbolic links in path.
For example, if I am at
/home/user/my-link/a
where my-link -> /mnt/user/
, i got to
/mnt/user/a
Explicitly passing new directory to tmux
does not work either:
tmux neww -c $(pwd)
Can I disable such dereferencing? I think I can write a workaround via tmux environment variables, but I want a clearer solution.
I am running tmux 1.8 from repos on Ubuntu 14.04.
Summaring all answers and comments from Philipp Wendler and Yacc, I came up with solution that works perfectly for me. I should mension that it uses some tricks on my machine, so they should be used carefully.
It was shown that tmux
can't solve problem on it's own, we need some tricks.
First, make that every pane describe it's path in tmux variable TMUX_<pane-id>_PATH
. That could be done via aliasing cd
or prompt code (I am using that), it doesn't matter:
# get $pane set to pane id without %
tmux set-environment TMUX_"$pane"_PATH $(pwd)
Second, have in path script tmux-neww.sh
. It sets NEWW
variable to current real path's way. It gets current pane-id as a param:
#!/bin/bash
pane=$(echo "$1" | tr -d '%')
pane_path=$(tmux show-environment TMUX_"$pane"_PATH | sed 's/^[^=]*=//g')
tmux set-environment NEWW "$pane_path"
tmux neww
Third, in tmux.conf
:
bind C \
run "tmux-neww.sh #{pane_id}"
Forth, I have in bash.bashrc
test, if shell is being run in tmux
. If so, it makes some changes (i.e. adds some variables that my heavy prompt will send some data to tmux variables). Here it tests, if NEWW is set:
neww=$(tmux show-environment NEWW 2> /dev/null | sed 's/^[^=]*=//')
if [ "$neww" != "-NEWW" ] && [ "$neww" != "" ] ; then
cd "$neww"
fi
tmux set-environment -r NEWW
That may be overwhelming, but works OK.