Restore tmux session after reboot

发布时间:2026-02-11 12:02

'Q&A session'是问答环节,'Closing remarks'是总结发言。 #生活技巧# #职场沟通技巧# #商务英语口语#

I do not save sessions per se, but since my set of sessions & windows & panes is mostly fixed (I add / remove some ad hoc but I don't need to "save" those), I wrote a script that creates the session for me after each reboot.

For inspiration, here's the script:

#! /bin/bash tmux new -s primary -n remoteServer -d sleep 1 tmux new -s nvim -n nvim -d sleep 1 tmux new-window -t primary -n projectA tmux new-window -t primary -n docs tmux new-window -t primary -n bin tmux new-window -t primary -n general sleep 3 tmux send-keys -t primary:projectA "cd /home/myuser/projectA/source" Enter tmux send-keys -t primary:docs "cd /home/myuser/projectA/docs" Enter tmux send-keys -t primary:bin "cd /home/myuser/somewhere/bin" Enter tmux send-keys -t nvim:nvim "nvim" Enter

This script creates two sessions (primary, nvim), primary has four windows (projectA, docs, etc...), then I pass cd commands to some of them to get to the directories in which I usually work in those windows. For nvim, I use mksession to save the session there (unrelated to the question here; I just run nvim in this script and do the rest in nvim itself).

I also have another setup where I need split panes so I use this script to create a grid of four panes in a window:

tmux split-window -v -t projectA:docs.0 sleep 1 # tmux renumbers the panes so the top two are '0' nad '1' now, the bottom one becomes '2' tmux split-window -h -t projectA:docs.0 sleep 1 tmux split-window -h -t projectA:docs.2 sleep 1 tmux send-keys -t projectA:docs.0 "cd /home/myuser/projectA/docs/builds" Enter tmux send-keys -t projectA:docs.1 "cd /home/myuser/projectA/docs/sources" Enter # and similarly for the remaining two panes

The -v and -h params are for vertical and horizontal splitting. The -t param is for session:window:pane desigantion.

After I run the script, I enter one of the sessions by tmux attach -t primary and then switch between them by <prefix> ) (e.g., alt+a ).

网址:Restore tmux session after reboot https://klqsh.com/news/view/337892

相关内容

How to close a tmux session
How to restore a browsing session from backup
Backup and restore with File History
Online Timer for 1 Minute. Start Your Countdown Free!
Yoga for Beginners – Easy Yoga Session at Home
20
Evaluating Meta (META) vs. Snap (SNAP): Which Stock to Choose After Q3 Earnings?
Water Damage Restoration & Repair Services
World Wetlands Day 2026 “Wetlands and Traditional Knowledge: Celebrating Cultural Heritage” — 2 February
Can you say “within 90 days after”?

随便看看