diff options
Diffstat (limited to 'tests/tmux-util/fake-tmux')
| -rwxr-xr-x | tests/tmux-util/fake-tmux | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/tests/tmux-util/fake-tmux b/tests/tmux-util/fake-tmux index 163ea24..b5a1e61 100755 --- a/tests/tmux-util/fake-tmux +++ b/tests/tmux-util/fake-tmux @@ -38,6 +38,19 @@ render_format() { echo "$out" } +# Render a tmux format string against one pane's fields. +# Args: format, name, pid, cmd, idx, cwd +render_pane_format() { + local out="$1" name="$2" pid="$3" cmd="$4" idx="$5" cwd="$6" + out="${out//\#\{pane_pid\}/$pid}" + out="${out//\#\{pane_current_command\}/$cmd}" + out="${out//\#\{pane_current_path\}/$cwd}" + out="${out//\#\{session_name\}/$name}" + out="${out//\#\{window_index\}/0}" + out="${out//\#\{pane_index\}/$idx}" + echo "$out" +} + case "$cmd" in list-sessions) fmt="" @@ -54,20 +67,33 @@ case "$cmd" in done ;; list-panes) + all=0 + fmt="" session="" while [ "$#" -gt 0 ]; do case "$1" in -t) shift; session="$1"; shift ;; - -F) shift; [ "$#" -gt 0 ] && shift ;; + -F) shift; fmt="${1:-}"; shift ;; -s) shift ;; + -a) all=1; shift ;; *) shift ;; esac done - read_state | while IFS=' ' read -r name attached pids _rest; do - if [ "$name" = "$session" ]; then - [ "$pids" = "-" ] || echo "$pids" | tr ',' '\n' - exit 0 + [ -n "$fmt" ] || fmt='#{pane_pid}' + read_state | while IFS=' ' read -r name attached pids activity windows cwd; do + [ -n "$name" ] || continue + if [ "$all" -eq 0 ] && [ "$name" != "$session" ]; then + continue fi + [ "$pids" = "-" ] && continue + idx=0 + for entry in $(echo "$pids" | tr ',' ' '); do + pid="${entry%%:*}" + cmd="${entry##*:}" + [ "$cmd" = "$entry" ] && cmd="shell" + render_pane_format "$fmt" "$name" "$pid" "$cmd" "$idx" "${cwd:-/tmp}" + idx=$((idx + 1)) + done done ;; display) |
