Canop / broot

A new way to see and navigate directory trees : https://dystroy.org/broot
MIT License
10.67k stars 234 forks source link

This shouldn't use ~/Library/Preferences on macOS #103

Closed lilyball closed 4 years ago

lilyball commented 4 years ago

Describe the bug After running broot, it wrote out data to a folder ~/Library/Preferences/org.dystroy.broot/. This is very surprising. The ~/Library/Preferences/ folder contains cfprefsd plists, and it's not somewhere that tools should be writing to directly. I'm also surprised to see it doing this at all since this is a command-line application, not a GUI application, and so it should just use the XDG Base Directory Specification locations instead.

If you really want to write to a Mac-like directory, then ~/Library/Application Support/org.dystroy.broot would be the place to use. But I'd really prefer it to just use the XDG dirs instead, e.g. ~/.config/broot/.

To Reproduce Steps to reproduce the behavior:

  1. Run broot

Expected behavior Any configuration it writes out should go to a sane location.

Configuration (please complete the following information):

Additional context It looks like this directory is coming from the directories library. Apple's documentation on ~/Library/Preferences very explicitly says you should not be creating your own files in that directory but only using NSUserDefaults or CFPreferences, and that ~/Library/Application Support is the right place to put configuration files. I will be filing an issue against directories as well, but in the meantime broot should switch to using data_dir() instead of config_dir() on macOS.

I'm not sure what the migration path for existing configuration will end up being if directories fixes their code, since you'll need a way to find the old path in order to migrate stuff. Hopefully the directories library can figure this out.

lilyball commented 4 years ago

I filed the upstream issue as https://github.com/soc/directories-rs/issues/62

Canop commented 4 years ago

I'm not sure I understand whether there's progress on the soc/directories side. Should I implement the change in broot directly ?

lilyball commented 4 years ago

If soc/directories isn't going to update then it would be a good idea to do it here. I hope they're willing to make the change in the library though.

skoskie commented 4 years ago

Seconding this issue. I've never seen a CLI tool place prefs in that directory. While I appreciate that there is a standard for placement of these kind of files, and that you adhered to that standard, It appears to me that the XDG standard does itself does not take correct MacOS conventions into account.

Most tools create a hidden directory directly in the user's home folder.

I just did a quick look through my ~/Library/Application Support/ directory and not a single CLI app is represented there. Conversely, configs for all my CLI apps exist directly in my $HOME directory, for example:

$HOME/
  .bashrc
  .gitconfig
  .yarnrc
  .vimrc
  .my.cnf   # MySql
  .oh-my-zsh/
  .iterm2/
  .gem/
  .emacs.d/
  .pip/
  .subversion/
  .vagrant.d/
  .vscode/  # Also exists in L/AS
  .npm/
  .docker/
  .bundle/
  .composer/
  .phpls/

You get the idea. This is just where CLI apps store configs, despite Apple's documentation, which I believe is focused on GUI apps.

To make this more confusing, the standard is a little different when using homebrew, but you might be interested in looking into this method as it may make your life much easier. Homebrew generally keeps all app-related files in a singular app directory (/usr/local/Cellar/<app>/<version> and symlinks the files to default places in the filesystem.

Obviously this is where your bin/broot file resides, but the other standard system-level directories can go in here as well.

Canop commented 4 years ago

soc recently made it clear he wasn't favorable to change his library. If somebody has a clean crate to suggest to handle this, I'd prefer not to code it myself

Canop commented 4 years ago

Changes were made in the library I use. The right solution for broot seems to be to look first for the new location, then for the second one, and only if both are empty write a new config in the new location. This involves one more lookup at every startup so this would probably be removed at some point between 2050 and 2060.

Canop commented 4 years ago

I don't have a mac for testing. I really need people to confirm it's OK, or tell me it's not, before I can deploy a new release.

You can test the master branch before the release. Don't hesitate to contact me on Miaou if needed.

kylebebak commented 2 years ago

I know this was already closed, and I have nothing new to say. Just confirming that IMO there shouldn't be a config file for a CLI tool in $HOME/Library/Application\ Support on macOS. As others have noted, config files for almost all CLI tools go directly in $HOME, and are almost always dotfiles

texastoland commented 9 months ago

Just want to document the current behavior. broot --install adds the script to XDG_CONFIG_HOME as expected with a symlink in the library. The only slightly unexpected behavior was not installing config files until the next run. I specifically ran into it trying to replace them with the latest version. A note in the docs about updating would help. Thanks for making it!