3 ms·
For those of us who nest tmux sessions: # Map a PID to a tmux session and window # in which to find that process (typically # $EDITOR): # function p2
by cryptonector 5y ago
For those of us who nest tmux sessions:
# Map a PID to a tmux session and window
# in which to find that process (typically
# $EDITOR):
#
function p2mux {
local fmt='#{session_name} #{window_index} #{pane_tty} #{window_name}'
find /tmp/tmux-$UID -type s -print0 |
xargs -0i tmux -S '{}' list-panes -a -F "$fmt" 2>/dev/null |
grep -w "$(ps -p "$1" -o tty= || echo pts/NO_SUCH_TTY)"
}
Yes, I nest tmux sessions. I've one session per-project, each running in a window of the same name in a top-level session. I've a different prefix for the top-level (^T) and the nested sessions (^A, because old habits from the days of screen(1) die hard). Every $EDITOR instance goes in a window named after the basename of the file being edited. `p2mux` is very useful in this setup.
Using `pane_pid` to make this more compact is tricky because I want to find processes that might be stopped and not running in the foreground.