When you start tmux the terminal emulator starts in your home directory. How to change the directory at startup?

For example, with cd ~/myprojects/test_project && tmux terminal starts at ~ and would like in test_project .

UPD:

Judging by the context matters. tmux i run under cygwin , mintty . As shell: zsh . To start trying to give birth to the script:

 #!/bin/sh export WORKDIR='/cygdrive/d/work/' PROJECT_DIR='cm' PROJECT_NAME='cm' PS3='Please enter your choice: ' options=("New session" "Quit") select opt in "${options[@]}" do case $opt in "New session") cd $WORKDIR if [ ! -d $PROJECT_DIR ] ; then mkdir -p $PROJECT_DIR fi cd $PROJECT_DIR tmux has-session -t $PROJECT_NAME 2>/dev/null if [ "$?" -eq 1 ] ; then echo "no session found. configuring..." tmux new-session -d -s $PROJECT_NAME #configuring windows tmux rename-window 'cm' tmux split-window -v tmux send-keys "cmd.exe" Cm tmux select-pane -t 1 tmux resize-pane -D 20 tmux send-keys "vim" Cm tmux select-window -t $PROJECT_NAME:1 else echo 'session found. connecting ...' fi tmux attach-session -t $PROJECT_NAME break ;; "Quit") break ;; *) echo invalid option;; esac done 

go to the right directory

  cd $WORKDIR if [ ! -d $PROJECT_DIR ] ; then mkdir -p $PROJECT_DIR fi cd $PROJECT_DIR 

is performed because echo $PWD shows the correct path.

just go to the correct directory and launch a new tmux session starts the shell in ~ .

  • absolute path try to specify. - Naumov
  • No, it does not help - Ivan Nazarov
  • What is the terminal worth? I look at everything works. ps it in bash_rc I understand? - Naumov
  • @Naumov mintty and zsh . I tried under bash - there is no effect - Ivan Nazarov

1 answer 1

Good day! You need to add to the environment variable of your login script (~ / .bash_profile for bash, ~ / .zprofile for zsh, ~ / .profile for mintty):

 export CHERE_INVOKING=1 

Resign and execute again:

 cd ~/myprojects/test_project && tmux 
  • Thanks, it worked. - Ivan Nazarov