From 1ef9b68d80da43d85b394c64247ce47e88b75e8d Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Wed, 20 Oct 2021 22:37:03 +0200 Subject: [PATCH] improved _pane_info() accuracy by excluding ssh proxy connections, tee, and only considering the first child of a process ps output is sorted by controlling terminal then pid in case of a cmd1 | cmd2 | cmd3 pipe chain, we only consider the first child of the parent process, which is cmd1 in the majority of cases the rare situation when pids wrap around isn't worth additional work on Linux - we sort ps output by lstart in hope precision is enough to make cmd1 always appear first even when pids wrap around - the more complex solution involves inspecting /proc//fd/0 to filter out processes being piped to finally, while lsof was promising, it won't list processes owned by other users unless run as root --- .tmux.conf | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index 3e3bdca..48f0117 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -501,8 +501,8 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # case "$_uname_s" in # *CYGWIN*) # ps -al | tail -n +2 | awk -v pane_pid="$pane_pid" -v tty="$pane_tty" ' -# ((/ssh/ && !/-W/) || !/ssh/) && $5 == tty { -# user[$1] = $6; parent[$1] = $2; child[$2] = $1 +# ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ && $5 == tty { +# user[$1] = $6; if (!child[$2]) child[$2] = $1 # } # END { # pid = pane_pid @@ -516,10 +516,24 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # } # ' # ;; +# *Linux*) +# ps -t "$pane_tty" --sort=lstart -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" ' +# ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ { +# user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4) +# } +# END { +# pid = pane_pid +# while (child[pid]) +# pid = child[pid] +# +# print pid":"user[pid]":"command[pid] +# } +# ' +# ;; # *) # ps -t "$pane_tty" -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" ' -# NR > 1 && ((/ssh/ && !/-W/) || !/ssh/) { -# user[$2] = $1; parent[$2] = $3; child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4) +# ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ { +# user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4) # } # END { # pid = pane_pid