lazygit/pkg/config
Blake Williams 21cad8eabe Add support for ~/.config/lazygit without setting XDG_CONFIG_HOME
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 https://github.com/jesseduffield/lazygit/issues/1341
2025-02-22 11:53:35 -05:00
..
app_config.go Add support for ~/.config/lazygit without setting XDG_CONFIG_HOME 2025-02-22 11:53:35 -05:00
app_config_test.go feat: Support multiple commit prefixes 2025-02-17 19:58:31 +01:00
config_default_platform.go Change OpenCommand to Open and OpenLinkCommand to OpenLink 2023-04-13 13:14:00 +02:00
config_linux.go Fix opening links containing ampersands (&) in WSL 2024-12-04 09:43:30 +01:00
config_windows.go Change OpenCommand to Open and OpenLinkCommand to OpenLink 2023-04-13 13:14:00 +02:00
dummies.go Make fields of AppConfig private 2024-08-18 10:24:52 +02:00
editor_presets.go Fix micro editor preset 2025-01-09 08:48:59 +01:00
editor_presets_test.go use 'suspend' instead of 'editInTerminal' internally 2023-08-09 22:03:58 +10:00
keynames.go Validate keybindings 2025-02-21 13:20:53 +01:00
user_config.go Add a gui.tabWidth config 2025-02-20 09:13:56 +01:00
user_config_validation.go Validate keys of custom commands 2025-02-21 13:20:53 +01:00
user_config_validation_test.go Validate keys of custom commands 2025-02-21 13:20:53 +01:00
xdg.go Add support for ~/.config/lazygit without setting XDG_CONFIG_HOME 2025-02-22 11:53:35 -05:00
xdg_darwin.go Add support for ~/.config/lazygit without setting XDG_CONFIG_HOME 2025-02-22 11:53:35 -05:00