Karabiner-elements: Request: Support ~/.config/ ($XDG_CONFIG_HOME)

Created on 23 Sep 2016  Â·  14Comments  Â·  Source: pqrs-org/Karabiner-Elements

A home folder gets very crowded if every program creates its own config files/folders there.
A standard alternative that is gaining traction is to place config files under ~/.config instead.
(At least, if you're not an OSX-only app that uses ~/Library/Application Support.)

For example, the fish shell uses ~/.config/fish/ and git looks for its config files under ~/.config/git/ out of the box.

It would be nice if we could place config files under ~/.config/karabiner/ instead of ~/.karabiner.d/. Karabiner-Elements could either do this by changing its default config folder, or by searching there if a config is not found at ~/.karabiner.d/.

stale

Most helpful comment

@lgarron the title should be corrected, "Request: Support ~/.config/ ($XDG_CONFIG_HOME)" should be changed to "Request: Support $XDG_CONFIG_HOME". Because $XDG_CONFIG_HOME should default to $HOME/.config.

https://wiki.archlinux.org/index.php/XDG_Base_Directory_support

All 14 comments

Looking at this a bit more, this standard comes from a project called XDG.

$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

The two programs I mentioned (fish and git) both support $XDG_CONFIG_HOME.

https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

Looking at the git implementation, a simple heuristic in constants.cpp should do (assuming you're willing to support it:

if (!once) {
  once = true;
  if (auto x = std::getenv("XDG_CONFIG_HOME")) {
    directory = x;
    directory += "/karabiner";
  } else if (auto p = std::getenv("HOME")) {
    directory = p;
    directory += "/.config/karabiner";
  }
}

However, that doesn't cover src/apps/PreferencesWindow/PreferencesWindow/Base.lproj/MainMenu.xib or src/apps/PreferencesWindow/PreferencesWindow/PreferencesWindowController.m

Great idea. Besides git and fish, neovim also uses XDG convention.

+1

I opened PR https://github.com/tekezo/Karabiner-Elements/pull/114 – this should do it.

+1

This seems to be the current standard for modern unixoid software, to unclutter the home directory. More info here and here.

Is there any chance that Karabiner-Elements will be ported to other Unices? I thought it was highly Mac specific.

@alanshutko this was not my suggestion (I think there is no reason to port it to other Unices), but macOS is a unixoid OS after all and many similar tools use the $XDG_CONFIG_HOME nowadays.

@lgarron the title should be corrected, "Request: Support ~/.config/ ($XDG_CONFIG_HOME)" should be changed to "Request: Support $XDG_CONFIG_HOME". Because $XDG_CONFIG_HOME should default to $HOME/.config.

https://wiki.archlinux.org/index.php/XDG_Base_Directory_support

Quite some time ago I submit a similar request to hammerspoon. Their solution is here: https://github.com/Hammerspoon/hammerspoon/pull/582 (the default path is set in the in the app plist in ~/Library, allowing users to change the value).

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

The default path has changed, so this bug should be considered fixed. :-D

Others may like to be able to configure the path using $XDG_CONFIG_HOME from default shell, but that's a follow-up feature as far as my request was concerned.

Very nice, bc of this feature one is able to cleanly backup the Karabiner-Elements config with his/her other Dotfiles.
Thanks for the great work!

Was this page helpful?
0 / 5 - 0 ratings