diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index eb5914f..000e436 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -1,5 +1,5 @@ alias z="exec zsh" -alias t="tmux a || ~/.config/tmux/tmux-sessionizer ~" +alias t=tmux_attach alias n=nvim_ve # alias vim=nvim_ve alias s="ssh-menu" diff --git a/zsh/scripts.zsh b/zsh/scripts.zsh index 17287b5..16e21b9 100644 --- a/zsh/scripts.zsh +++ b/zsh/scripts.zsh @@ -79,3 +79,19 @@ function tssh { ssh -t "$@" "command -v tmux && (tmux a || tmux new-session -s gorazd -c ~) || bash" } + +function tmux_attach { + tmux_running=$(pgrep tmux) + + if ! [[ -z ${TMUX} ]]; then + echo "already attached; refreshing env" + source <(tmux show-environment | sed -n 's/^\(.*\)=\(.*\)$/export \1="\2"/p') + return 1 + fi + + if [[ -z $tmux_running ]]; then + ~/.config/tmux/tmux-sessionizer ~ + else + tmux a + fi +}