zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.95k stars 1.17k forks source link

Store state files in $XDG_STATE_HOME by default #3185

Open bartekpacia opened 6 months ago

bartekpacia commented 6 months ago

This PR is targeted at #3176

bartekpacia commented 6 months ago

@JoeKar So far I only updated the docs. Please let me know if such changes make sense, so I can start implementing them.

dmaluka commented 6 months ago

This isn't gonna be backwards compatible, is it?

bartekpacia commented 6 months ago

I was thinking about it, but in the initial proposal I decided to omit this. But I definitely would like to make this change completely painless for everyone. Making anyone lose time over such a minor change would be unprofessional.

By "backward compatibility", do you mean that if ~/.config/micro/backups and ~/.config/micro/buffers exist, they should be used and whatever is in ~/.local/state/micro should be ignored?

Another option would be to copy ~/.config/micro/backups and ~/.config/micro/buffers to ~/.local/state/micro.

dmaluka commented 6 months ago

Dunno. Neither option seems perfect.

JoeKar commented 6 months ago

The backward compatibility will be a nasty thing.

Another option would be to copy ~/.config/micro/backups and ~/.config/micro/buffers to ~/.local/state/micro.

In that case you will do this with every startup, right? Maybe it's better to move it then and maintain the new location only. :thinking:

bartekpacia commented 6 months ago

Maybe it's better to move it then and maintain the new location only.

Yeah, it's also an option.

The situation where the change I'm planning to make would cause problems seems very rare: Micro would have to crash, the user would have update in the meantime, and then the backup would be missing.

clipcarl commented 3 months ago

micro_state_dir.patch.txt

Here is a patch to separate micro's state files from micro's config files. With this patch files that were previously searched for in $MICRO_CONFIG_HOME/buffers or $MICRO_CONFIG_HOME/backups are now searched for in $MICRO_STATE_HOME/buffers or $MICRO_STATE_HOME/backups respectively. If $MICRO_STATE_HOME/buffers does not exist $XDG_STATE_HOME/micro/buffers is used instead. If that doesn't exist either $HOME/.local/state/micro/buffers is used. Ditto for $MICRO_STATE_HOME/backups.

This patch simply adds a config.StateDir variable (alongside the existing config.ConfigDir) and uses it for state stuff. The patch will create the state directory if it doesn't already exist but does not touch the old location.

I don't do anything for migration because IMO it's not worth adding code that will sit in micro forever to address the minor one-time slight annoyance of history and cursor positions being reset. I think a small external migration script would be better for that (not included).

If anyone would like to test this without the hassle of building micro from source a statically linked binary for 64-bit Linux (x86_64) can be found here. It should work on any x86_64 Linux distribution. A statically linked binary for 64-bit Arm Linux (aarch64) can be found here for those of you using 64 bit ARM servers or Pis.

Andriamanitra commented 3 months ago

@clipcarl could you make the change as a Github pull request to make it easier to review?

clipcarl commented 3 months ago

@clipcarl could you make the change as a Github pull request to make it easier to review?

Honestly I've never used Github for development (I'm old-school) so I'm not sure how to do that!

clipcarl commented 2 months ago

?