#!/usr/bin/env sh
#
# txpane - `tmux select-pane` with fzf

if [ "$1" = "-w" ]; then
  # if run in a separate tmux window using keybinds, ignore the last window
  tag=$(tmux list-panes -s -F "#{session_name}:#{window_index}.#{pane_index} #{pane_current_command} #{pane_title}" | head -n -1 | fzf -0 -1 | awk '{ print $1 }')
else
  tag=$(tmux list-panes -s -F "#{session_name}:#{window_index}.#{pane_index} #{pane_current_command} #{pane_title}" | fzf -0 -1 | awk '{ print $1 }')
fi

tmux select-pane -t "${tag}"
tmux select-window -t "${tag}"
