tmux: Fix session chooser without fzf
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.
This commit is contained in:
parent
0487042d7e
commit
d91adbfc13
1 changed files with 19 additions and 15 deletions
|
@ -6,19 +6,19 @@ exist() { type "$1" >/dev/null 2>&1; }
|
||||||
# shellcheck disable=2139
|
# shellcheck disable=2139
|
||||||
alias tmux="tmux -f ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
|
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
|
# fzf
|
||||||
if exist fzf; then
|
if exist fzf; then
|
||||||
# fzf select a tmux session to connect to, with pane preview
|
# 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
|
fi
|
||||||
|
|
||||||
fzf_tmux_session() {
|
_fzf_tmux_list_sessions() {
|
||||||
if [ -z "$1" ]; then
|
tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf \
|
||||||
result=$(
|
|
||||||
tl | fzf \
|
|
||||||
--layout=reverse \
|
--layout=reverse \
|
||||||
--height=50% \
|
--height=50% \
|
||||||
--border \
|
--border \
|
||||||
|
@ -26,7 +26,11 @@ fzf_tmux_session() {
|
||||||
--preview="tmux_pane_tree {}" \
|
--preview="tmux_pane_tree {}" \
|
||||||
--preview-window=right:99% \
|
--preview-window=right:99% \
|
||||||
--print-query
|
--print-query
|
||||||
)
|
}
|
||||||
|
|
||||||
|
_fzf_tmux_attach_start_session() {
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
result=$(_fzf_tmux_list_sessions)
|
||||||
case "$?" in
|
case "$?" in
|
||||||
0)
|
0)
|
||||||
# found a session, attaching
|
# found a session, attaching
|
||||||
|
|
Loading…
Reference in a new issue