-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
kitty @ ls output session #8876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@kovidgoyal I printed it, and it was different from what I expected, can you give me some more guidance on how to deal with it?
def _set_current_layout(self, layout_name: str, layout_state: dict[str, Any] | None = None) -> None:
self._last_used_layout = self._current_layout_name
self.current_layout = self.create_layout_object(layout_name)
self._current_layout_name = layout_name
if layout_state:
print("before -- ", layout_state)
v = self.current_layout.unserialize(layout_state, self.windows)
print("serialize -- ", v)
print("after -- ", self.current_layout.serialize(self.windows))
self.mark_tab_bar_dirty() output:
|
There you go: 97f1d7f and the variable name is wrong in your sample session file. |
Now it works fine. @kovidgoyal I'm planning to integrate kitty-save-session into Can it be generated in the ~/.config/kitty/ directory by default? When the user specifies the filepath, it will be generated to the specified path. |
On Wed, Aug 06, 2025 at 07:09:18PM -0700, zhaolei wrote:
zzhaolei left a comment (kovidgoyal/kitty#8876)
Now it works fine.
@kovidgoyal I'm planning to integrate [kitty-save-session](https://github.com/dflock/kitty-save-session) into kitty @ ls --output-session=[filepath], what do you think? This will generate a session file(like startup.conf)
I haven't looked at the code in that project but in general the concept
should be fine. Some notes:
1) As I said before skip transient windows aka ones with actions defined
on them
2) When serializing env vars for the launch commandline be careful to escape them properly. launch is parsed using shell lexing rules. Use the as_str_literal() function to do it.
3) Probably add a new command to the session file so that all the common
env vars can be defined once globally instead of in every launch
command.
4) Exclude a bunch of unsafe env vars when serilizing, see the
parse_message() method in kitty/launch.py probably factor that out
into a common function and use it.
5) You have to handle overlay windows.
6) You have to decide how much window state to serialize. launch has a
lot of options. Think about things like window and tab titles, allow
remote control password, markers, OS Window class/name, logos, margins,
watchers, panels, hold after ssh, etc.
Can it be generated in the ~/.config/kitty/ directory by default? When the user specifies the filepath, it will be generated to the specified path.
Instead of --output-session, use --output-format which can take choices
json and session. Then output to stdout, the user can redirect the output
wherever they like.
|
I will implement it step by step and finally achieve the effect of
This is a good idea, I'll implement it. |
@kovidgoyal On Mac, every time I start ./kitty/launcher/kitty, an
|
Now you can generate a session file by running the following command: kitty @ ls --output-format session |
8ea0bd7
to
bac0a24
Compare
No idea, doesnt happen on my mac, but in any case you should be running kitty/launcher/kitty.app/Contents/MacOS/kitty |
To be honest, I don't quite understand the logic of parse_message. Is the logic in kitty/launch.py:1005 what I need to focus on? |
@kovidgoyal Sorry, I'm afraid I don't fully understand these requirements. Could you please implement them when you have time? Not sure if the current implementation meets certain requirements |
On Thu, Aug 07, 2025 at 08:30:04PM -0700, zhaolei wrote:
zzhaolei left a comment (kovidgoyal/kitty#8876)
> 4) Exclude a bunch of unsafe env vars when serilizing, see the parse_message() method in kitty/launch.py probably factor that out into a common function and use it.
To be honest, I don't quite understand the logic of parse_message. Is the logic in kitty/launch.py:1005 what I need to focus on?
|
On Thu, Aug 07, 2025 at 08:32:42PM -0700, zhaolei wrote:
zzhaolei left a comment (kovidgoyal/kitty#8876)
> 2/3/4/5/6
@kovidgoyal Sorry, I'm afraid I don't fully understand these requirements. Could you please implement them when you have time?
OK.
|
|
There's also a whole bunch of display manager related env vars. A subset: XAUTHORITY XDG_SESSION_TYPE XMODIFIERS XSERVTransSocketUNIXPath Wayland XDG_SESSION_TYPE XDG_RUNTIME_DIR WAYLAND_DEBUG QT_QPA_PLATFORM GDK_BACKEND Other Related Environment Variables CLUTTER_BACKEND Thinking about it, it may be better to only serialize env vars that are not present in kitty's own environment. Or even better, only serialize env vars that were specified when the window itself was created, this will require some plumbing to track those env vars on the window object. |
This is a bit beyond my capabilities, so I'm afraid I'll just have to rely on you to figure this out.🙁 |
Could we just snapshot the env vars when a window is created and diff them when serialization happens? Furthermore, could we move forward with no env var support for now and add that is a later feature? I personally don't want env vars being recorded in my sessions. |
On Fri, Aug 08, 2025 at 02:11:38PM -0700, Mike Lloyd wrote:
mike-lloyd03 left a comment (kovidgoyal/kitty#8876)
Could we just snapshot the env vars when a window is created and diff them when serialization happens?
Furthermore, could we move forward with no env var support for now and add that is a later feature? I personally don't want env vars being recorded in my sessions.
The whole approach here needs rethinking. What needs to be done is the
restoring only the settings that were used to create the window. For
that there needs to be plumbing in place to record those settings. This
applies definitely to things like env vars and cmdline. For the rest of
the settings will need to be reviewed on a case by case basis. cwd for
instance should probably be the current not initial cwd.
|
Could we target an MVP that just restores tabs, windows, layouts, and cwds? What other data, besides env vars are you hoping to capture during a user's session? If we want to restore actively running commands like nvim, we may want to include a prompt in each window for the user to confirm running the command when a session is restored. That's how Zellij does it for reference. |
On Fri, Aug 08, 2025 at 10:10:15PM -0700, Mike Lloyd wrote:
mike-lloyd03 left a comment (kovidgoyal/kitty#8876)
Could we target an MVP that just restores tabs, windows, layouts, and cwds? What other data, besides env vars are you hoping to capture during a user's session?
No, I am not going to waste my time building half baked solutions and
then fixing them later.
If you want a half baked solution I suggest you contribute to the third
party save session tool. Now that I have implemented layout restoring it
should be trivial to finish that with whatever level of functionality
you want.
As for built-in session save/restore I will get to it when I have the
time to address it properly.
If we want to restore actively running commands like nvim, we may want to include a prompt in each window for the user to confirm running the command when a session is restored. That's how Zellij does it for reference.
This is very much a matter of taste/workflow. Running the active command
rather than the underlying shell (if any) makes sense for some active command,
not for others.
|
I'm not asking for "half-baked" solutions. I'm merely making a suggestion and trying to figure out how I can best contribute. You said the approach needs rethinking. So I threw some ideas out there. Anyway, I'm happy to contribute to this feature so you're free to focus on more pressing issues. But I don't want to waste your or my time pursuing an approach you're not a fan of. If you can define the required elements for session restoration, that gives me a clear roadmap to work towards. My understanding right now is that built-in session save/restore needs the following elements:
Does this look right? |
Defining what is needed and how it will work is basically 90% of the
task. Writing the actual code once that's done is trivial, so by asking
me to do that now, you are basically asking me to do the whole thing.
I will do that, *when I am ready to do it*. Until then, be patient,
or work out of tree on the existing solution, which, now that I have
done layout serialization can cover most use cases.
|
Fine, man. I'm just trying to help. I understand that FOSS software is difficult with people trying to demand things of you free of charge. I'm grateful for this project and what you've build here so I'm trying to do the opposite of that by contributing. But you seem pretty set on what you want and that isn't very clear to me. I'll leave it be and you can implement it if and when and how you want. |
If you want to help, be patient, wait till I implement it, then once |
Have added boss.serialize_state_as_session() I leave testing/refinement to you. Any comments/changes/discussion is welcome now. |
kitty/tabs.py:1194 When there is only one tab, self.active_tab_history is empty, so the tab cannot be serialized. Is this expected? |
On Tue, Aug 12, 2025 at 02:52:22AM -0700, zhaolei wrote:
zzhaolei left a comment (kovidgoyal/kitty#8876)
kitty/tabs.py:1194
When there is only one tab, self.active_tab_history is empty, so the tab cannot be serialized. Is this expected?
No, fixed, thanks.
|
kitty/boss.py:512 This will disrupt the user's current tab position and reorder them accordingly, but this shouldn't be necessary. kitty/tabs.py:1201 Also, a new_os_window will be created here, but this isn't necessary when there's only one OS window. |
Both issues should be fixed now. |
c1d434f
to
f121981
Compare
Is there a way to distinguish between tab and window focus? if window.os_window_id == current_focused_os_window_id() and window is self.active_window:
gw.append('focus') |
Now the main functionality should be implemented. The only thing missing is the focus distinction between tabs and windows, or how to focus the last open tab |
On Tue, Aug 12, 2025 at 04:46:01AM -0700, zhaolei wrote:
zzhaolei left a comment (kovidgoyal/kitty#8876)
Is there a way to distinguish between tab and window focus?
The currently active tab should automatically be the last tab in the
serialized session file which means it should become the active tab
automatically as well.
See da7ac31
|
Now generate the following session content:
Visiting directories |
Is there anything I haven't done yet? |
On Tue, Aug 12, 2025 at 05:34:14AM -0700, zhaolei wrote:
zzhaolei left a comment (kovidgoyal/kitty#8876)
Now generate the following session content:
Visiting directories `1, 2, 3, 4, 2` (also tab numbers) will result in a session with tabs in `1, 3, 4, 2`. Most recently visited will be placed last? This makes sense, but it should probably be documented somewhere.
See if this helps:
214dc73
|
I'm getting an error when trying to use a desktop session created with
Here's the session I'm trying to restore from:
Running |
This is a preliminary implementation and doesn't work yet. I'm not sure what the problem is.
expect:
./kitty/launcher/kitty -c NONE --session ~/.config/kitty/startup.conf
startup.conf: