From 0d0c0adaa74604c52b9642ddfeee0705e05fd4e5 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Fri, 3 Oct 2025 12:19:35 +0200 Subject: [PATCH] feat(tmux): add `tmx` function for attaching or creating a tmux session (#53) Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/53 --- .bash_aliases | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.bash_aliases b/.bash_aliases index 1d91502..c623285 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -5,10 +5,6 @@ alias phpa="sudo update-alternatives --config php" # Kill all code-server processes. Sometimes it hangs on startup alias kvscode="ps uxa | grep .vscode-server | awk '{print $2}' | xargs kill -9" -# Tmux split commands, "q" for fast access, "w" for horizontal (right of q), "a" for vertical (below q) -alias qw="tmux split-window -h" -alias qa="tmux split-window -v" - # +-------------------+ # | Directory & Files | # +-------------------+ @@ -197,3 +193,23 @@ sshl () { ssh -p 2222 "$user"@local.vlw.se } + +# +------+ +# | Tmux | +# +------+ + +# Tmux split commands, "q" for fast access, "w" for horizontal (right of q), "a" for vertical (below q) +alias qw="tmux split-window -h" +alias qa="tmux split-window -v" + +tmx() { + # Check if any tmux sessions exist + if tmux has-session 2>/dev/null; then + # Attach to the first existing session + tmux attach-session -d -t $(tmux ls | head -n 1 | awk '{print $1}' | tr -d :) + + return 0 + fi + + tmux new-session -s default +} \ No newline at end of file