diff --git a/tmux/.config/sh/alias.d/tmux.sh b/tmux/.config/sh/alias.d/tmux.sh index 20277a9..57a95a5 100644 --- a/tmux/.config/sh/alias.d/tmux.sh +++ b/tmux/.config/sh/alias.d/tmux.sh @@ -6,27 +6,31 @@ exist() { type "$1" >/dev/null 2>&1; } # shellcheck disable=2139 alias tmux="tmux -f ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf" -# show a list of running tmux sessions -alias tl='tmux list-sessions -F "#{session_name}" 2>/dev/null' - # fzf if exist fzf; then # fzf select a tmux session to connect to, with pane preview - alias tm='fzf_tmux_session' + alias tm='_fzf_tmux_attach_start_session' + alias tl=tm +else + alias tm='tmux_attach_start' + # show a list of running tmux sessions + alias tl='tmux list-sessions -F "#{session_name}" 2>/dev/null ' fi -fzf_tmux_session() { +_fzf_tmux_list_sessions() { + tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf \ + --layout=reverse \ + --height=50% \ + --border \ + --prompt="Session> " \ + --preview="tmux_pane_tree {}" \ + --preview-window=right:99% \ + --print-query +} + +_fzf_tmux_attach_start_session() { if [ -z "$1" ]; then - result=$( - tl | fzf \ - --layout=reverse \ - --height=50% \ - --border \ - --prompt="Session> " \ - --preview="tmux_pane_tree {}" \ - --preview-window=right:99% \ - --print-query - ) + result=$(_fzf_tmux_list_sessions) case "$?" in 0) # found a session, attaching