zyedidia / micro

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

Request: improve conformance with the XDG Base Directory Specification #2004

Open jwatt opened 3 years ago

jwatt commented 3 years ago

micro appears to create the file ~/.config/micro/buffers/history, which is not a configuration file. Data generated from the use of an app should be put under ${XDG_DATA_HOME:-~/.local/share}, so it seems like the buffers directory should live at ${XDG_DATA_HOME:-~/.local/share/micro/buffers}. Would you mind updating micro to use that path?

Many thanks for micro, it's awesome. 😄

Commit hash: cfcb2e4 OS: Fedora 33 Terminal: Konsole/bash

0x5c commented 3 years ago

This would be great, especially with config/dotfile management systems. With the current behaviour, it's impossible to just track ~/.config/micro/, one has to individually track each config files (settings.json, bindings.json, colorschemes/, etc).

There is already an option to use a custom directory for backups, so this could be implemented similarly for the other things.

adrianinsaval commented 2 years ago

Also ~/.config/micro/backups should probably be on ~/.cache/micro/backups instead

0x5c commented 2 years ago

Either of data home (.local/share) or state home (.local/state) would seem more appropriate for the backups, especially state since it is defined in the spec at the place for command history, undo history, etc The current version of the spec is here

da2x commented 2 years ago

Also ~/.config/micro/backups should probably be on ~/.cache/micro/backups instead

The ./backup/* directory is configurable (backupdir). However, it does belong in the $XDG_CACHE_HOME directory rather than $XDG_CONFIG_HOME as-is the current default.

The ./buffers/history file belongs in the $XDG_STATE_HOME/micro/ directory.

The ./buffers/* directory belongs in the $XDG_CACHE_HOME/micro/ directory. (It, arguably, belongs in $XDG_STATE_HOME/micro/ when the savecursor option is enabled (off by default). However, overall it’s closer to cache data than state data.)


3 Migration strategy

Option A:

  1. Check if the lastmigration option in the in settings.json file.
    1. If not present or matches a version number lower than the current version number:
      1. Move the ${XDG_CONFIG_HOME:-$HOME/.config}/micro/buffers/history file to ${XDG_STATE_HOME:-$HOME/.local/state}/micro/history. (Skip if the source file doesn’t already exist.)
      2. Move the ${XDG_CONFIG_HOME:-$HOME/.config}/micro/buffers/ directory to ${XDG_CACHE_HOME:-$HOME/.cache}/micro/buffers/. (Skip if the source directory doesn’t already exist.)
      3. Move the ${XDG_CONFIG_HOME:-$HOME/.config}/micro/backups/ directory to ${XDG_CACHE_HOME:-$HOME/.cache}/micro/buffers/. (Skip if the source directory doesn’t already exist.)
      4. Add "lastmigration": $current_version_number to the settings file.
    2. If present and equal to the current or a higher version number, then abort.

Option B:

Just leave the old files in their current location and begin using the new locations. You’ll still likely get 99.8 % user-satisfaction.


Alternative approaches

  1. Leave the ./buffers and ./backup directories inside $XDG_CONFIG_HOME. When these folders are created (no migration strategy), mark them as cachy/trashy directories. Automatically add a CACHEDIR.TAG file into each directory. Also, set the extended attributes com.apple.metadata:com_apple_backup_excludeItem with a value of [empty] (MacOS) and xdg.robots.backup with a value of false (Linux) on each directory. Lots of backup and search utilities will know to ignore them by default. There’s nothing equivalent on Windows.
  2. Add buffersdir and historyfile configuration options but leave the current defaults (or take the opportunity to adjust their defaults with the implementation of these options).
clipcarl commented 2 months ago

I've submitted a patch (and a link to a Linux test binary) in #3185.