tmux-resurrect
tmux-resurrect copied to clipboard
Add a function to save/restore only a specific session
I would love to see a "per session" handling instead saving the whole server.
Here is the idea: I have a teamocil config for the bigger projects, which are spawned in the morning. When the day goes on I add new windows/panes to log some stuff or edit a special file(s) in its own place. Day ends with additional mini sessions, which have no name and only some windows ... stuff. I thought to save a clean, good working state of a session so it is easily possible to restore a clean state of this session (aka project/task). At the end of the day you just kill the server with all the mess you created. At the next morning you can spawn your saved sessions one after the other when you need them. This makes manual crafting of session files obsolete and sessions are able to evolve easily. I hope you like the idea :-)
Hi, thanks for sharing the idea.
At the next morning you can spawn your saved sessions one after the other when you need them.
Interesting idea. Is there something in your workflow that makes you want to restore session one by one, instead of just restoring them all together?
I don't have the necessity for this in my own workflow but I'll give it a thought.
Interesting idea. Is there something in your workflow that makes you want to restore session one by one, instead of just restoring them all together?
I have one main project (aka work ^^) and a lot of on going side projects. By starting only what I need, I have less clutter in the Tmux session list. This makes switching between sessions easier, because the list is shorter and only filled with "active" stuff. I only restart my PC once a week, so my Tmux server runs pretty long. Another point is the amount of running (not used) processes like unit tests which watch for changes of files or something similar.
I don't have the necessity for this in my own workflow but I'll give it a thought.
Can you explain your workflow, please? I would appreciate some new thoughts on this topic :smile:
Okay that makes sense. You don't want to restore "helper" sessions that make noise in the list and make switching sessions harder and slower.
Perfectly reasonable, and in fact I had the same problem until I made tmux-sessionist - specifically the prefix + g
binding that has the goal to speed up session switching. (btw. g is a mnemonic for "goto session")
With it, if you want to switch to work
session, you just type: prefix + g
w<Enter>
and you are there. Notice, only the first letter of the session name is typed - the rest is "auto-completed" presuming you have only one session starting with the letter "w".
You don't have to look and visually "parse" the session list, then type j/k to select it (this is ultra slow btw). You just think of a session name you need, type 1 or 2 first letters and bang, you're there.
This is the principle I learned in the vim community and it's called "tell don't parse" (or something similar). To achieve the speed, the goal is to "tell" the tool what you want to do, instead of visually parsing/reading options available to you and then choosing.
So, as a result of that thinking, I don't really worry about the session list or it's size. Currently I have ~25 sessions. Some of them are not used for a couple days and that's completely fine since they don't come into way.
Since you asked about the workflow, another thing I'd say I don't do in tmux is "garbage collection". Tmux makes everything cheap. Panes, windows, sessions - they all come at no cost or penalty to create, own and just have around, even if you don't use it. Noone should worry about maintaining the state of tmux windows or sessions. They are all cheap, so why bother and waste time. So, if you do some experimentation and create a couple new windows or a session - that's fine. No need to feel obliged to "clean up" after you did that. And who knows, you might even need it later.
With the "tell don't parse", "garbage collection" and "everything is cheap" thoughts out, the decision about "which session to restore" becomes easier - I think. For me, it's: I don't want to bother or think - I just want everything as it was. It's all cheap anyway.
So there you go - does that give you some ideas? Let me know!
Perfectly reasonable, and in fact I had the same problem until I made tmux-sessionist - specifically the prefix + g binding that has the goal to speed up session switching.
Great :+1: This solves the switching problem for me I think. Especially "jump to last session" key binding is great time saver!
This is the principle I learned in the vim community and it's called "tell don't parse" (or something similar). To achieve the speed, the goal is to "tell" the tool what you want to do, instead of visually parsing/reading options available to you and then choosing.
I'm using vim for years now but didn't see this principle so clearly descriped, thank :)
Panes, windows, sessions - they all come at no cost or penalty to create, own and just have around, even if you don't use it.
I think you talking about this sentence of my last post:
Another point is the amount of running (not used) processes like unit tests which watch for changes of files or something similar. I meant the process running inside a pane can be a problem. But I setup tmux-ressurect and tmux-sessionlist and test how it affects the overall performance.
So, thanks for the great discussion ;)
Closing this discussion as it's been a while and it seems it didn't generate additional interest from other users. If anyone has anything to add to this, please feel free to reopen.
In my workflow, I open a new session for a project. After finish a project, I close its session, while some day I want to reopen that project in a new session. In this situation, save and restore only a specific session is useful.
Thanks for the interesting discussion. I'd like to add that with my workflow, being able to restore specific sessions would still be useful. I have half a dozen projects that I'm working on at a given time, and each one might have it's own dependencies of background running processes that may not be cheap to run. Frequently I have separated django preview server processes, redis, postgres, and nginx containers for each project. Currently, when I cd into the project directory, the docker containers for that respective project will run. If I cd into another project, it will have it's own dependencies run. For simplicity, I always run postgres, redis, the debug server etc. on the default ports. I realize I could leave the containers running for all my projects simultaneously if I just use different ports for each project. It would get messy pretty quickly to manage ports not clashing.
Ideally, if I could activate a session for a project, then I would only run the containers I need and without any worry of collision.
With the prevalence of docker these days, I feel my workflow is not uncommon among web developers.
Thanks for the great project!
I'd definitly use that. I tend to create a whole session per ticket, with a lot of different "tabs" for different tasks, themselves splited most of the time in different windows. There are sessions that I'd like to be save on disk, but not loaded in RAM. Just so I could go back to it when I want to. I guess it doesn't take that much memory though. Would be also very cool if it was in the exact same state that I left it. :D
+1, it would be great.
Thanks for your work
I'd like to request that this be re-opened.
This issue does fit with my workflow, but despite my own workflow, the main reason I think this should be provided is programmability. I didn't expect tmux-ressurect
to support my exact workflow. Instead I'd hoped there is some api to save and restore a particular session by name so that I could use my own config and keybindings to set it up.
My Workflow (if it helps)
I use a session per project. I might be working on projects A
, B
and C
but I won't get to A
or C
for another few weeks and I'm just using B
for now. What happens now is that I have to save it when all 3 sessions are running. If I want to close A
and C
and keep working with B
and then store B
again, I can't do that since A
and C
would be lost.
I use tmux on my laptop and not a server which is why I'd much rather close A
and C
than leave them running.
Ping @bruno-
+1
@bruno- could this be reopened? I find that it's not cheap to have all sessions on RAM. For example I work on different projects with different dependencies, multiples instances of neovim (with language servers, which are not cheap)... It will be useful to be able to save/restore a single session only.
I think someone should step up and take the lead on this feature. Frankly, I don't see it added to this repo. I think it should be developed as another plugin or a fork of this plugin.
I've made a quick set of functions in my .zshrc
:
tmux_sessions_path="/home/<user>/.tmux/resurrect"
tmux_resurrect_scripts="/home/<user>/.tmux-resurrect/scripts"
tmux_save() {
cp -P $tmux_sessions_path/last $tmux_sessions_path/last_copy
$tmux_resurrect_scripts/save.sh
cp $tmux_sessions_path/last $tmux_sessions_path/$1.txt
mv $tmux_sessions_path/last_copy $tmux_sessions_path/last
}
tmux_load() {
cp -P $tmux_sessions_path/last $tmux_sessions_path/last_copy
ln -sf $tmux_sessions_path/$1.txt $tmux_sessions_path/last
$tmux_resurrect_scripts/restore.sh
mv $tmux_sessions_path/last_copy $tmux_sessions_path/last
}
To use this:
- save all sessons (ctrl + b => ctrl + s)
- close all sessions not related to projecta =>
tmux_save myprojecta
- reload all sessions (ctrl + b => ctrl + r)
- close all sessions not related to project b =>
tmux_save myprojectb
- repeat for each project
- then you can
tmux_load myprojecta
Notes:
- If you load multiple project it won't close other session but this seems a feature to me.
- This functions needs to be run in tmux, otherwise it will crash.
- I've made this quickly but it seems to work. If someone want to wrap this nicely somewhere, feel free.
Edit: If you save more than one session it will fail to restore. Solution, save multiple individual session
Edit 2: Seems that https://github.com/tmuxinator/tmuxinator make what I wanted to achieve.