summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2026-02-26 20:09:06 +0000
committerDavid T. Sadler <davidtsadler@googlemail.com>2026-02-26 20:09:06 +0000
commita0199c67449d2039029103972d013b9ac9226139 (patch)
treee52899d3f26f889e89cab0d72654eaaec747be82
parente20fe89771d227b8fcff9c80321cf537a9447ccb (diff)
Improve tm bash function so that sessions are restored
-rw-r--r--bash/.bash_aliases27
1 files changed, 20 insertions, 7 deletions
diff --git a/bash/.bash_aliases b/bash/.bash_aliases
index 7ec2ad1..0eafcad 100644
--- a/bash/.bash_aliases
+++ b/bash/.bash_aliases
@@ -17,16 +17,29 @@ alias ras='sudo nixos-rebuild switch --flake .#'
# Tmux
tm() {
+ # Handle specific session attachment (standard behavior).
if [ -n "$1" ]; then
- # If an argument is provided, try to attach to it or create it.
tmux attach-session -t "$1" 2>/dev/null || tmux new-session -s "$1"
- elif tmux has-session 2>/dev/null; then
- # No argument? Open the alphabetical list.
- tmux attach-session \; choose-tree -sZ -O name
- else
- # Nothing running? Fresh start.
- tmux
+ return
fi
+
+ # If no tmux server is running at all.
+ if ! tmux has-session 2>/dev/null; then
+ # Start a dummy session in the background to kickstart the server.
+ tmux new-session -d -s "init"
+
+ # Trigger the restore script.
+ RESURRECT_SCRIPT="$HOME/.config/tmux/plugins/tmux-resurrect/scripts/restore.sh"
+
+ if [ -f "$RESURRECT_SCRIPT" ]; then
+ tmux run-shell "$RESURRECT_SCRIPT"
+ # Kill the dummy session once restored.
+ tmux kill-session -t "init" 2>/dev/null
+ fi
+ fi
+
+ # Attach and show the tree.
+ tmux attach-session -t "main" 2>/dev/null || tmux attach-session \; choose-tree -sZ -O name
}
# Edit NixOS Sops secret files.