Open terminal in current directory with tmux
I have a simple .bashrc
file at the moment that allows me to always open the same terminal (reopen, actually) running tmux. The important part is shown below.
The essence of this is that when you execute tmux attach -d
you disconnect any tmux
session that is running, effectively closing the terminal window that is open (since I opened it with the tmux
command). tmux
is still running however, so calling a terminal with tmux attach -d
reopens that session thanks to a little line in the tmux config file.
This works great but now I'd like to have the functionality back that opens a terminal window in the directory where I click "open terminal here".
I understand I would have to to the following:
- Tell
tmux
to "C-m C" (create new panel) -
cd
to the current directory
Is this possible? I have a very limited knowledge of this sort of things, hence I'm asking.
I have been looking around and found this gist (also shown below). It makes sense but I don't know how to get the ${TARGET}
variable inside the .bashrc
file.
.bashrc
116 # Start tmux every time we call up a terminal
117 [[ $TERM != "screen" ]] && exec tmux attach -d
tmux.conf
1 #if run as "tmux attach", create a session if one does not already exist
2 new-session -n $HOST
The gist file
tmux_pwd () {
[ -z "${TMUX}" ] && return
TARGET=\-t$(tmux display-message -p "#S")
tmux set-window-option ${TARGET} default-path $PWD > /dev/null
(( sleep 300;
tmux set-window-option ${TARGET} default-path ~/Development > /dev/null; ) & ) > /dev/null 2>&1
}
alias pwd="\pwd; tmux_pwd"
Tmux always opens with your present working directory.
Like, if you are in /home/user/Desktop/, tmux session will start from this path only.
And please elaborate your question.