Skip to content

Instantly share code, notes, and snippets.

@markshust
Created January 7, 2026 12:30
Show Gist options
  • Select an option

  • Save markshust/15ca1adc0f5bb93208b68da71b9ec935 to your computer and use it in GitHub Desktop.

Select an option

Save markshust/15ca1adc0f5bb93208b68da71b9ec935 to your computer and use it in GitHub Desktop.
Configure ZSH for creating tmux sessions and auto-attaching windows for sync between mobile + desktop
# Auto-start tmux (attach to existing session or create new)
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
if [ -z "$SSH_CLIENT" ]; then
# Local terminal: create new window in last used directory
DIR=$(tmux showenv LAST_DIR 2>/dev/null | cut -d= -f2)
tmux new-session -t main \; new-window -c "${DIR:-$HOME}" 2>/dev/null || tmux new -s main
else
# SSH (Termius): just attach to existing session
tmux attach -t main 2>/dev/null || tmux new -s main
fi
fi
# Track current directory for new tmux windows
_update_tmux_dir() {
if [ -n "$TMUX" ]; then
tmux setenv LAST_DIR "$PWD"
fi
}
precmd_functions+=(_update_tmux_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment