Skip to content
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

Support .config/XDG configuration location in MacOSX #1341

Open
briandipalma opened this issue May 28, 2021 · 6 comments · May be fixed by #3989
Open

Support .config/XDG configuration location in MacOSX #1341

briandipalma opened this issue May 28, 2021 · 6 comments · May be fixed by #3989
Labels
enhancement New feature or request

Comments

@briandipalma
Copy link
Contributor

If both Linux and MacOSX supported the same directory for configuration it would make it easier to script machine setup. In fact some of the Rust based tools I use only support the .config directory, it'd be a rare developer who doesn't have that directory on their Mac.

@briandipalma briandipalma added the enhancement New feature or request label May 28, 2021
@mjarkk
Copy link
Contributor

mjarkk commented Jul 23, 2021

I think we are not going to make the above the default because:

If we would start over i think .config would indeed a better solution for a cli applications but i just don't think it's worth changing the location for x many users that already have config files.
Don't forget that we also follow the spec on windows so it's not far fetched to do the same thing on mac then and if we would default to ~/.config we should also talk about using that on windows to.

Nevertheless you should be able to set $CONFIG_DIR to configure a specific config dir but that doesn't seem to work correctly as it literally places the config files in that dir and i think we should instead place the lazygit config folder inside the $CONFIG_DIR.
I'll fix the found issue.

Have you tried setting $XDG_CONFIG_DIRS in your shell config?

@jesseduffield
Copy link
Owner

jesseduffield commented Jul 27, 2021

I'm cool to support this, we'd just need to find a way to make it backwards compatible. I don't really like the idea of us moving the current config files to a different directory upon lazygit being updated, but am willing to be persuaded that's actually a good move.

If we don't go ahead with a migration, we could use the following rules:

  1. if the user has a .config/lazygit directory, use it
  2. if the user does not have a .config/lazygit directory, but does have an XDG spec directory for lazygit, use it (i.e. existing users will stay in the old directory unless they move it themselves)
  3. if the user has neither (i.e. on first installing lazygit), create the directory .config/lazygit and use that.

As @mjarkk says you can use the CONFIG_DIR env variable to set the directory as ~/config/lazygit. It was an oversight to expect /lazygit to be specified there: it certainly seems superfluous, but I don't think CONFIG_DIR is actually that common a thing in other places (based on a google search).

Lemme know your thoughts

@briandipalma
Copy link
Contributor Author

Have you tried setting $XDG_CONFIG_DIRS in your shell config?

No, I use a variable in my Ansible scripts that is set per host:

https://github.com/briandipalma/ansible/blob/main/roles/common/tasks/lazygit.yml#L16
https://github.com/briandipalma/ansible/blob/main/group_vars/all.yml
https://github.com/briandipalma/ansible/blob/main/host_vars/Brians-MacBook-Pro.local.yml

I prefer to keep my shell config clean and lean on Ansible to deal with machine/workstation variations where possible.

This works fine but I can imagine other users may want to symlink a bunch of directories into ~/.config or may want to just copy a bunch of directories into ~/.config and so a change to support that path would be helpful for them. I raised this issue more for other/future users than myself as I've already handled the different paths.

I think the rules @jesseduffield describes make sense, personally I have to dig around/google to find the correct paths in MacOSX while I know ~/.config and can cd in there without a second thought. I'd say that's a similar story for most heavy CLI/*nix based users.

I mean ~/Library/Application Support/. That's a GUI world file path if I ever saw one.

@dehlen
Copy link

dehlen commented Sep 2, 2021

Since I am managing all my dot files with stow it would be great to be able to include the lazygit configuration here as well. Any plans on supporting the config folder next to the Application Support location?

@nadeemkhedr
Copy link

I think by now it's the default for most apps to have the config in the ~/.config directory in macos, would be great if lazygit supports that as well

@jesseduffield
Copy link
Owner

jesseduffield commented Jan 17, 2022

Sorry for not getting back to this thread in a while. I'm currently working on some refactoring but will happily review a PR implementing the above approach (i.e. #1341 (comment)) (using the backwards-compatible approach)

BlakeWilliams added a commit to BlakeWilliams/lazygit that referenced this issue Oct 12, 2024
Currently lazygit looks for its config file in `XDG_CONFIG_HOME` if it's
available, but if not it falls back to the defaults defined by the
[xdg](https://github.com/adrg/xdg) package. Unfortunately the defaults
the package falls back to isn't what CLI applications commonly fall back
to on macOS. Specifically, it looks in `~/Library/Application Support`
instead of `~/.config`.

This updates the app config logic to:

- Look for `~/.config/lazygit` first if `XDG_CONFIG_HOME` is not set
  and we're on macOS.
- Fallback to the existing `xdg` package location if the configuration
  file exists there.
- Default to `~/.config/lazygit/config.yml` if `XDG_CONFIG_HOME` is not
  set, we're on macOS, and there is no existing configuration file.

This change did feel a bit like having to thread a needle and I didn't
see any existing tests for this behavior (which is reasonable, since it's
complicated and OS dependent) so I did test a few variations of the
configuration locally by building with this change included and running
a `brew` installed lazygit.

It seemed to work properly, falling back to the existing location when
`XDG_CONFIG_HOME` isn't set, using `~/.config/lazygit` when `config.yml`
is present, and creating `~/.config/lazygit/config.yml` when it's not.

I think this should resolve jesseduffield#1341
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants