0

I'm looking for a way to do something like this without attaching to the session.

tmux attach-session -c <directory> -t <session>
                    ^^^^^^^^^^^^^^

Per tmux(1), there isn't a way to change the default working directory (new windows and new panes) of an entire session without attaching to it.

I cannot attach to the session because I'm doing this in some automated scripts where attaching would break the automation.

iBug
  • 3,428
  • 1
  • 24
  • 57
  • potential duplicate: https://unix.stackexchange.com/questions/281994/changing-the-current-working-directory-of-a-certain-process – Adrian Feb 13 '19 at 16:02

2 Answers2

0

Does

`tmux send-keys -t <session> 'cd <directory>'`

do what you want?

Unsure if this would apply to new windows / panes created after this, but the poor man's workaround would be just to send this to <session>:<windowID>.<paneID> after creating that window/pane.

jeremysprofile
  • 666
  • 7
  • 19
-1

You can simply

tmux attach -c directory -t session 2> /dev/null &

the attaching will exit immediately as the forked background job is not a terminal. But it will succeed in changing the working directory of the tmux session.

Edit: I corrected -s with -t but the trick does not seem to work anymore in tmux 3.1b.

katosh
  • 369
  • 2
  • 13