Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cygwin + tmux on windows 7 - why won't tmux use the current path?

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?

like image 838
toadjamb Avatar asked Oct 18 '14 01:10

toadjamb


3 Answers

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

like image 192
kraiz Avatar answered Oct 15 '22 04:10

kraiz


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

like image 20
anishpatel Avatar answered Oct 15 '22 05:10

anishpatel


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

like image 1
drobok Avatar answered Oct 15 '22 06:10

drobok