24

I have used tmux on linux systems and Mac OSX with no problem. I am aware that as of version 1.9 (I have 1.9a according to tmux -V), you are required to do something along the lines of tmux split-window -c "#{pane_current_path}". That doesn't work, though. Nothing seems to work.

The best "hint" I can give is that the -c parameter appears to be recognized in some form, as I get an error about an invalid path if I give it an explicit path that I know does not exist. However, giving it an explicit path does nothing (I thought maybe there was a problem with using pane_current_path.

There is a chance there are two questions here, as tmux does not start in the current folder, which is default behavior, I believe.

Anybody know what's going on? Is this expected behavior? Am I missing a library somewhere?

toadjamb
  • 934
  • 1
  • 9
  • 14
  • I'm not sure what the downvote is about... My only assumption (since there is no direct feedback) is that it is from someone who is not familiar with cygwin and/or tmux, so I'm not sure why there were here to begin with.If maintaining the current path works out of the box for others, that sure would be nice to know. – toadjamb Oct 19 '14 at 06:55
  • 1
    Just installed tmux on cygwin, seeing this same issue. Did you ever find a solution? – nfarrar May 11 '15 at 22:05
  • 1
    @nfarrar - kraiz answered with the solution, which the OP failed to acknowledge and accept. – self. Jul 31 '15 at 15:31

4 Answers4

25

With the following in your .tmux.conf::

set-environment -g CHERE_INVOKING 1

Then tmux split-window -c "#{pane_current_path}" drop me at/, but tmux split-window -c $PWD works.

Found at http://article.gmane.org/gmane.comp.terminal-emulators.tmux.user/5921

kraiz
  • 2,178
  • 1
  • 22
  • 22
16

kraiz's answer using set-environment and $PWD did not work for me.

Instead, I set the environment variable in my login script (~/.bash_profile for bash, ~/.zprofile for zsh):

export CHERE_INVOKING=1

Also, $PWD did not work for me, but #{pane_current_path} did. Here's a snippet of my .tmux.conf:

bind c new-window -c "#{pane_current_path}"
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"

Software: tmux 2.0, Cygwin 1.7.35, zsh 5.0.6, Windows 10

Community
  • 1
  • 1
anishpatel
  • 1,472
  • 1
  • 16
  • 23
1

That solution instead of CHERE_INVOKING used above will preserve your symlink path:

# .bashrc
# set pwd for tmux
function set_tmux_pwd() {
    [ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#D" | tr -d %) "$PWD"
    return 0
}
function my_cd() {
    \cd $1
    set_tmux_pwd
}
set_tmux_pwd
alias cd=my_cd

and

# .tmux.conf
# this support symbolic link
bind c run-shell 'tmux new-window "cd \"$(tmux show-environment $(echo "TMUXPWD_#D" | tr -d %) | sed -e "s/^.*=//")\"; exec $SHELL"'
bind '"' run-shell 'tmux split-window -v "cd \"$(tmux show-environment $(echo "TMUXPWD_#D" | tr -d %) | sed -e "s/^.*=//")\"; exec $SHELL"'
bind '%' run-shell 'tmux split-window -h "cd \"$(tmux show-environment $(echo "TMUXPWD_#D" | tr -d %) | sed -e "s/^.*=//")\"; exec $SHELL"'

https://github.com/tmux/tmux/issues/1282#issuecomment-559033047

It works on cygwin 3.1.4 and tmux 2.6

drobok
  • 11
  • 1
  • 2
0

#{pane_current_path} always left me at /. "$PWD" always left me at ~. I uninstalled the ubuntu package and compiled from the github master branch and now it works perfectly with #{pane_current_path}.

Marcel
  • 1,034
  • 1
  • 17
  • 35