micro icon indicating copy to clipboard operation
micro copied to clipboard

Global settings config file support

Open alexminder opened this issue 4 years ago • 10 comments

Description of the problem or steps to reproduce

In micro, your settings are stored in ~/.config/micro/settings.json

According to doc micro uses only user settings file. Would be great to supprt global config, like /etc/micro/settings.json for every user.

Specifications

micro-2.0.8

alexminder avatar May 24 '21 15:05 alexminder

@zyedidia Is it possible to implement the feature?

alexminder avatar Aug 22 '21 07:08 alexminder

You can provide a different config directory location with the MICRO_CONFIG_HOME environment variable, or by using the config-dir flag. Does this address what you want to do?

zyedidia avatar Aug 22 '21 16:08 zyedidia

It would be nice to be able to keep two config dirs around, and overlay the user config on top of the global config. For instance, if a distro doesn't ship with sudo it can set sucmd in the global config file and then the user can set whatever other options they want in ~/.config

AdrianVovk avatar Aug 22 '21 17:08 AdrianVovk

I have the same feature request. @AdrianVovk proposed a good solution that's intuitive & standard for many different Linux applications (e.g. tor, bash, nano, but AFAIK nvim lacks this feature).

I suggest supporting configuration similar to the following:

  1. Default global config in /etc/micro:
├── plug
│   └── [...global plugin storage]
├── syntax
│   └── [...example syntax highlight files]
├── [...other supported dirs that make sense to be global, w/ examples]
├── bindings.json
└── settings.json
  1. Local config in ~/.config/micro:
├── buffers
│   └── history
├── plug
│   └── user_installed_plugin_001
├── [...other supported dirs]
├── bindings.json
└── settings.json
  1. Changes in ~/.config/micro should overwrite /etc/micro "atomically", "unit by unit", i.e. config entry per config entry, not file per file.

@zyedidia what do you think of this?

AFAIK, multi-source config management can be achieved with Viper library.

tsilvs avatar Sep 08 '24 14:09 tsilvs

The suggested setup would help me support a global micro setup for all users on a few systems. Currently I use the MICRO_CINFIG_HOME to point to the configuration for all users. But they obviously cannot write all their backups and buffers there. in settings.json I have "backupdir": "~/.config/micro/backups", but I cannot get savecursor working. I assume because the buffers are not saved. Any workaround for this?

Bert

BertLindeman avatar Aug 29 '25 21:08 BertLindeman

Any workaround for this?

They could all have their own config directories (i.e. ~/.config/micro/ as usual) but with settings.json, bindings.json, init.lua, plug, colorschemes, syntax being symlinks to some global files?

To avoid the need for such hassle, we (or you?) could probably implement an option similar to backupdir for specifying a custom buffers directory instead of ~/.config/micro/buffers.

dmaluka avatar Aug 30 '25 09:08 dmaluka

Will try your suggested setup and report back.

A built-in setup for buffers like backupdir if it supports globbing with e.g. ~ and $USER would be really nice.

Bert

BertLindeman avatar Aug 30 '25 10:08 BertLindeman

To avoid the need for such hassle, we (or you?) could probably implement an option similar to backupdir for specifying a custom buffers directory instead of ~/.config/micro/buffers.

I think we should just follow the XDG base directory specification and store the buffers in $XDG_STATE_HOME/micro/ (~/.local/state/micro/) on Linux by default. Backups don't really belong in the config directory either ($XDG_STATE_HOME would be more appropriate) but since we already have a setting for using a different directory there's no real need to mess with it.

related: #2004 #3176

Andriamanitra avatar Aug 30 '25 14:08 Andriamanitra

I think we should just follow the XDG base directory specification and store the buffers in $XDG_STATE_HOME/micro/ (~/.local/state/micro/) on Linux by default. Backups don't really belong in the config directory either ($XDG_DATA_HOME would be more appropriate) but since we already have a setting for using a different directory there's no real need to mess with it.

related: #2004 #3176

That sounds even better. But that would be future work, so I'll go on for myself with the symlinks. And that is also work in process.

BertLindeman avatar Aug 30 '25 15:08 BertLindeman

Not tested to the bones, but this works. The contents of ~/conf/micro:


drwxr-xr-x 2 root root 4096 Aug 30 17:53 backups/
lrwxrwxrwx 1 root root   41 Aug 30 17:53 bindings.json -> /usr/local/share/micro-conf/bindings.json*
drwxr-xr-x 2 root root 4096 Aug 30 18:12 buffers/
lrwxrwxrwx 1 root root   40 Aug 30 17:53 colorschemes -> /usr/local/share/micro-conf/colorschemes/
lrwxrwxrwx 1 root root   36 Aug 30 17:53 init.lua -> /usr/local/share/micro-conf/init.lua*
lrwxrwxrwx 1 root root   32 Aug 30 17:53 plug -> /usr/local/share/micro-conf/plug/
lrwxrwxrwx 1 root root   41 Aug 30 17:53 settings.json -> /usr/local/share/micro-conf/settings.json*
lrwxrwxrwx 1 root root   34 Aug 30 17:53 syntax -> /usr/local/share/micro-conf/syntax/

BertLindeman avatar Aug 30 '25 16:08 BertLindeman