3 ms·
My approach to tmux session management is the following tm() { if [ -z $1 ]; then tmux list-sessions return fi tmux det
by michaelmior 10y ago
My approach to tmux session management is the following
tm() {
if [ -z $1 ]; then
tmux list-sessions
return
fi
tmux detach -s $1 2> /dev/null
tmux attach-session -t $1 2> /dev/null || tmux new-session -s $1
}
_tm() {
local word completions
word="$1"
sessions=`tmux list-sessions 2> /dev/null`
[ $? -ne 0 ] && return
completions=`echo "$sessions" | cut -d ':' -f1`
reply=( "${(f)completions}" )
}
compctl -K _tm tm
I don't find I need to persist sessions, I just want a quick way to switch between them. This gives me a tm command that autocompletes session names and creates new sessions if they don't exist. It also detaches existing clients since I only ever connect once and this way I don't have to deal with issues of differing terminal sizes.