7

Is there anyway to find out information about the current working directory of any pane from within a tmux session?

I'd like to write a bash script that changes the directory of the current pane to the directory of another pane, even if that pane has a program or script already running in it.

The way I'd like to do it is to navigate to pane 1, then I'd goto pane 2, hit a hot key and pane 2 would now change to the same pwd as pane 1.

2
  • 1
    Does this work: tmux display-message -p -F "#{pane_current_path}" -t0? Commented May 7, 2015 at 12:02
  • yeah that does seem to work... totally add that as an answer!
    – Brad Parks
    Commented May 7, 2015 at 12:14

1 Answer 1

18
tmux display-message -p -F "#{pane_current_path}" -t0
6
  • 1
    sweet! this totally worked... and for what it's worth, here's the simple script I put together to allow me to switch the current panes directory to the directory of the last accessed pane. tmux last-pane; DIR=$(tmux display-message -p -F "#{pane_current_path}"); tmux last-pane; cd $DIR, and this can be bound in your ~/.tmux.conf using bind f run "tmux_last_dir" where tmux_last_dir contains the script mentioned before. This would allow you to hit TMUX_PREFIX + f to switch your current pane's folder using the script.
    – Brad Parks
    Commented May 7, 2015 at 12:46
  • 1
    I'm glad that you like it :) This is what SE is for! Commented May 7, 2015 at 12:48
  • 1
    yeah I spent about an hour playing around with it, and didn't know about the display-message command, which I somehow missed in the man page. That's going to be super useful in itself.... Thanks again!
    – Brad Parks
    Commented May 7, 2015 at 12:58
  • 1
    You are actually saving my life!
    – arainone
    Commented Feb 5, 2016 at 17:31
  • 1
    This works perfectly. It was just what I was looking for! I activate the pane, detach and if I execute this I get that current path.
    – muammar
    Commented Aug 31, 2020 at 19:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .