Based on previous answers I found a way that has fewer disadvantages. I'm working on tmux -V
= next-3.4
.
tmux new-window -c /some/linked/path
itself also derefences things, so even if you manage to get a hold of your current path un-dereferenced it doesnt help yet. For me it only works reliably to do set-environment PWD /some/linked/path \; new -window -c /some/linked/path
.
The behavior with PWD
is only loosely documented at the very end of the man page, but it does what you want in this case.
tmux set-environment PWD /some/linked/path
however is global to the session, so simply doing that in your shell prompt everytime you change the path will mix up things. Because it will use the folder you last hit enter on, not the folder of the current pane.
The workaround for that is to use "#{pane_path}"
instead of "#{pane_current_path}"
(see tmux man page). This is local to the pane and you can control it via escape sequences in your shell prompt.
For zsh that is
function _send_cwd_for_tmux {
[[ ! -v TMUX ]] && return
d=$(print -P '%d')
printf "\033]7;$d\033\\"
}
and then just silently add that to your chpwd
hook
add-zsh-hook chpwd _send_cwd_for_tmux
For reference, here's what I have in my tmux config:
# new windows/panes start in the current pane's directory
# NOTE
# - "#{pane_current_path}" is already with symlinks dereferenced
# - "#{pane_path}" comes from a escape code to inform the terminal of CWD
# - we use that to inform tmux about the symlinked version of CWD
# - this happens in zsh prompts everytime the CWD changes
# - all the -c options also dereference things, unless PWD points to the same place
# NOTE
# "#{pane_current_path}" is already with symlinks dereferenced, it comes from /proc/self/cwd
# "#{pane_path}" comes from an escape code to inform the terminal of CWD, unset unless you do it
# we set that in zsh's prompt everytime, it's local to the terminal, not tmux
# new-window -c still dereferences things
# unless PWD points to the same thing
# (this behavior is only half-documenten in tmux, very end of man page)
bind-key c set-environment -F PWD "#{pane_path}" \; new-window -c "#{pane_path}"
bind-key % set-environment -F PWD "#{pane_path}" \; split-window -h -c "#{pane_path}"
bind-key '"' set-environment -F PWD "#{pane_path}" \; split-window -c "#{pane_path}"
# new window to the right of current window, not appended at the end (as default)
# note: default C is for customize-mode
bind-key C set-environment -F PWD "#{pane_path}" \; new-window -a -c "#{pane_path}"