Get current directory of last tmux pane

I’m looking for a tmux command to obtain the current directory (#{pane_current_path}) of the last focused pane, that doesn’t require switching to it and switching back.

The following works:

tmux last-pane
echo "$(tmux display-message -pF "#{pane_current_path}")"
tmux last-pane

however I was wondering if there is a way to do this without having to call tmux last-pane twice (perhaps a variable that contains the ID of the last pane?).

Asked By: kwyntes


You can use tmux‘s display-message sub command with -t (target-pane)1 flag. For example you can run

tmux display-message -p -t ! "#{pane_current_path}"

will show details of last pane.


Answered By: davidt930
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.