From 5629270ba2ffd3669100ceca439e9b76a0e2e878 Mon Sep 17 00:00:00 2001 From: Ted Kulp Date: Wed, 28 Feb 2024 06:54:20 -0500 Subject: [PATCH] tm function to auto-attach if session exists --- .config/zsh/tmux.zsh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.config/zsh/tmux.zsh b/.config/zsh/tmux.zsh index 51e701b..d72d726 100644 --- a/.config/zsh/tmux.zsh +++ b/.config/zsh/tmux.zsh @@ -1,2 +1,35 @@ alias xssh="xpanes --ssh" alias tmux="tmux -2" + +_tm.getCurrenSession() tmux display-message -p '#S' + +tm() { + local targetSession=${1:='main'} + + # if outside tmux + [[ -z "$TMUX" ]] && tmux new -A -s ${targetSession} && return $? + + if [[ "`_tm.getCurrenSession`" = "$targetSession" ]] + then print "You did not move."; return 1 + fi + + # Create session if it doesn't exists + tmux new -d -s ${targetSession} 2>/dev/null + + tmux switch-client -t ${targetSession} +} + +_tm() { + (( $CURRENT > 2 )) && return 0 + + local tmuxList=( `tmux ls -F "#{session_name}"` ) + + # if outside tmux + [[ -z "$TMUX" ]] && _describe 'command' tmuxList && return 0 + + local currentSession=( `_tm.getCurrenSession` ) + local actualList=(${tmuxList:|currentSession}) + _describe 'command' actualList +} + +compdef _tm tm