dotfiles/tmux/.config/sh/alias.d/tmux.sh
Marty Oehme 348a167390 Fix tmux vim navigator movement
Fixes tmux xdg-compliance (and, more importantly, Tmux Plugin Manager's)
by setting the environment variable TMUX_PLUGIN_MANAGER_PATH to follow
xdg specifications. Tmux, due to not being xdg-compliant, needs to be
aliased to start with the `-f` option pointing into the configuration
directory.

Fixes tmux vim nagigator's controls being overwritten by other control
schemes in tmux.
2020-02-06 20:49:15 +01:00

53 lines
1.2 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"
# 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'
fi
fzf_tmux() {
if [ -z "$1" ]; then
result=$(
tl | fzf \
--layout=reverse \
--height=50% \
--border \
--prompt="Session> " \
--preview="tmux_pane_tree {}" \
--preview-window=right:99% \
--print-query
)
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