Marty Oehme
d91adbfc13
If no fzf is installed, session chooser will now be the old manual session name input. `tm session-name` will attach or create a session of the same name, whether fzf is installed or not. If invoked without argument, and fzf is installed will show a list of sessions to choose from. If fzf is missing, will create new session based on current directory. `tl` has been changed to display the old non-interactive list if no fzf exists. If fzf has been found however, it points to `tm` instead, since invoking it without arguments fulfills the same function.
57 lines
1.3 KiB
Bash
57 lines
1.3 KiB
Bash
#!/usr/bin/env sh
|
|
|
|
exist() { type "$1" >/dev/null 2>&1; }
|
|
|
|
# alias tmux to follow xdg-specification
|
|
# shellcheck disable=2139
|
|
alias tmux="tmux -f ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
|
|
|
|
# fzf
|
|
if exist fzf; then
|
|
# fzf select a tmux session to connect to, with pane preview
|
|
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_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=$(_fzf_tmux_list_sessions)
|
|
case "$?" in
|
|
0)
|
|
# found a session, attaching
|
|
tmux_attach_start "$(echo "$result" | tail --lines=1)"
|
|
;;
|
|
1)
|
|
# did not find a session, creating
|
|
result=$(echo "$result" | head --lines=1)
|
|
# if . was only thing entered, create one for current dir
|
|
if [ "$result" = "." ]; then
|
|
tmux_attach_start
|
|
# create for query name
|
|
else
|
|
tmux_attach_start "$result"
|
|
fi
|
|
;;
|
|
esac
|
|
else
|
|
tmux_attach_start "$1"
|
|
fi
|
|
}
|
|
|
|
unset choice
|
|
unset -f exist
|