This commit is contained in:
Aiden Hall 2018-04-17 20:52:04 +00:00 committed by GitHub
commit b21f634fca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 2 deletions

View File

@ -36,6 +36,8 @@ if which tmux &> /dev/null
# systems without the proper terminfo
[[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color"
ZSH_TMUX_SESSION_NAME_PREFIX="`whoami`-zsh-tmux-"
# Get the absolute path to the current directory
local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)"
@ -58,6 +60,22 @@ if which tmux &> /dev/null
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf"
fi
# helper functions
function _incr() {
var=$(($1 + 1))
echo $var
}
function _inactive_sessions {
INACTIVE_SESSIONS=`tmux ls | grep -v attached | grep "$ZSH_TMUX_SESSION_NAME_PREFIX" | cut -d: -f1`
[[ -n $INACTIVE_SESSIONS ]] && echo $INACTIVE_SESSIONS
}
function _all_sessions {
ALL_SESSIONS=`tmux ls | grep "$ZSH_TMUX_SESSION_NAME_PREFIX" | cut -d: -f1`
[[ -n $ALL_SESSIONS ]] && echo $ALL_SESSIONS
}
# Wrapper function for tmux.
function _zsh_tmux_plugin_run()
{
@ -65,10 +83,16 @@ if which tmux &> /dev/null
if [[ -n "$@" ]]
then
\tmux $@
# Try to connect to an existing session.
# Try to connect to an existing named session.
elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]
then
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` attach || \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session
# See if we need to create a new named session
if [[ `_inactive_sessions | wc -l` != 0 ]]
then
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` attach -t `_inactive_sessions | head -n1`
else
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session -s "$ZSH_TMUX_SESSION_NAME_PREFIX`_incr $(_all_sessions | tail -n1 | cut -d- -f4)`"
fi
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
# Just run tmux, fixing the TERM variable if requested.
else