I am going to be as precise and brief as possible in my explanation of the issue that I am experiencing. If this is helpful use it, I have a MacBook Air Sonoma 14.4.1.
I installed Tmux on my system a while back and recently updated it. I am expecting to work on many different projects therefore I created a directory for the different projects. When I start the Terminal, I am in my profile directory. What I would like to do is start a new tmux session and automatically be brought into the projects directory. I have done some online research on this and looked into some previous stackoverflow posts. I found adding the command new-session -c /ProjectsPath
in the Tmux configuration file almost accomplish what I want.
Now the issue is, when there isn’t a Tmux server and you start a brand new Tmux session with the command tmux
in the Terminal. Two sessions are automatically created. Session 0 is in /ProjectsPath
. Session 1 is in /MyProfilePath
. If I don’t kill the current tmux sessions, and keep creating new sessions. All the new sessions are in the /MyProfilePath
not in the projects directory. I haven’t found a way to only start a new Tmux session in the desired directory without automatically creating two sessions.
I tried adding the code kill-session
in the configuration after the new-session -c /ProjectsPath
command. This does kill one of the sessions, however it’s the wrong one. It kills Session 0 which currently in the desired directory while leaving Session 1 which is not in the desired directory. I tried specifying which session to kill by adding this kill-session -t 1
into the configuration only to receive the message: “can’t find session: 1”.
I tried replacing new-session -c /ProjectsPath
with attach-session -c /ProjectsPath
which gives the message “no session” when you start a brand new session.
Any ideas?
Charles Florestal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.