How do I get a tmux session's base directory?
1
vote
1
answer
968
views
I have been using
tmux
for a few months, and there is one thing that always bothered me: when I type cd
into my shell, I get moved into my home directory (this is the standard behavior of cd
, so nothing unexpected).
What I would like to have is that I get into the current tmux session's base directory, and this could probably easily be implemented via a shell function:
cd () {
if [ $# -eq 0 ]
then
command cd $TMUX_BASE_DIR # fictional environment variable
else
command cd $@
}
However, I have not found a way to find this directory. tmux does not have a build-in command apparently nor sets an environment variable. I also skimmed over the man page, but didn't find anything in the COMMANDS
or VARIABLES
section. This directory needs to be saved somewhere though, as opening a new tmux window makes it go to this directory.
Of course one I open a new window and close one everytime I want to achieve the desired behavior, but this is surely less than optimal and there needs to be a better way.
Is there a way to achieve this behavior / get the session base directory in tmux? If so, how?
Asked by leo848
(111 rep)
Nov 12, 2022, 02:58 PM
Last activity: Nov 12, 2022, 03:57 PM
Last activity: Nov 12, 2022, 03:57 PM