dotfiles/tmux/.local/bin/tmux_pane_tree
Marty Oehme 92376839a4 Add tmux fzf session chooser
Added tmux session chooser. Aliased to `tm`, calling `tmux_attach_start`
(the original tm script).

When called without arguments displays a fzf list of currently running
tmux sessions, with a preview to their respective open panes. A session
can be chosen in fzf which tmux will attach itself to. When creating a
query in fzf which does not have a valid target and confirming, tmux
will automatically create that session and attach itself to it.

When called with an argument, tmux will attach itself or create a
session of the same name. If called with the name of a session file, as
before, tmux will automatically execute that session file and attach
itself to it.
2020-02-02 23:44:23 +01:00

21 lines
778 B
Bash
Executable file

#!/usr/bin/env bash
# create a tree-style view
# of all open tmux panes
# and the command they are currently running
tmux ls -F'#{session_id}' | while read -r s; do
S=$(tmux ls -F'#{session_id}#{session_name}: #{T:tree_mode_format}' | grep ^"$s")
session_info=${S##$s}
session_name=$(echo "$session_info" | cut -d ':' -f 1)
if [[ -n "$1" ]] && [[ "$1" == "$session_name" ]]; then
echo -e "\033[1;34m$session_info\033[0m"
tmux lsw -t"$s" -F'#{window_id}' | while read -r w; do
W=$(tmux lsw -t"$s" -F'#{window_id}#{T:tree_mode_format} - #{pane_current_command}' | grep ^"$w")
H=$(tmux lsw -t"$s" -F'#{window_id}#H' | grep ^"$w")
echo "${W##$w}" | sed "s/\"${H##$w}\" //"
done
else
echo -e "\033[1m$session_info\033[0m"
fi
done