Hammerspoon: Is it possible to move the hammerspoon configuration?

Created on 2 Oct 2015  Â·  8Comments  Â·  Source: Hammerspoon/hammerspoon

I _really_ hate clutting up $HOME with hundreds of files. I typically keep my application configurations in $XDG_CONFIG_HOME (~/.config/<application>/). Looked around and read through the docs, but didn't see a way to change this. Am I missing it? If it's not possible, any chance it might be in the future?

Most helpful comment

The reason for the widespread use of ~/.config/<application_name> is because it's part of the XDG Base Directory Specification. The /.config/<application_name> path is the _default_ path used for user configuration files. It makes it _very_ easy to version control all your dotfiles and sync them between machines.

All 8 comments

At present, no.

The location of MJConfigFile is hard coded in the source to "~/.hammerspoon/init.lua".

You could put the following at the top of ~/.hammerspoon/init.lua so that any _other_ hammerspoon config files could be found in ~/.config/hammerspoon:

package.path = os.getenv("HOME").."/.config/hammerspoon/?.lua;"..os.getenv("HOME").."/.config/hammerspoon/?/init.lua;"..package.path
package.cpath = os.getenv("HOME").."/.config/hammerspoon/?.so;"..package.cpath

@cmsj, while I've not considered this specifically for Hammerspoon before, I have noticed (and mostly like) a trend in many unix based things moving configuration files into ~/.config... do you object to checking a MJConfigFile entry in the application user defaults and defaulting to the current location if it's not present? Other than setting this var in variables.m, can you think of other places to check for impact?

On Oct 2, 2015, at 4:21 PM, Nathan Farrar [email protected] wrote:

I really hate clutting up $HOME with hundreds of files. I typically keep my application configurations in $XDG_CONFIGHOME (~/.config//). Looked around and read through the docs, but didn't see a way to change this. Am I missing it? If it's not possible, any chance it might be in the future?

—
Reply to this email directly or view it on GitHub https://github.com/Hammerspoon/hammerspoon/issues/579.

@cmsj - re-reading this, it may not be clear -- I'm willing to do the work, and I know what needs to be done in the above specified file, just looking for pointers on other places it might affect (setting up the search paths in setup.lua I think is one... are there others that you can think of off the top of your head?)

The reason for the widespread use of ~/.config/<application_name> is because it's part of the XDG Base Directory Specification. The /.config/<application_name> path is the _default_ path used for user configuration files. It makes it _very_ easy to version control all your dotfiles and sync them between machines.

@asmagill I think search paths should be it. I'm generally in favour of doing this, the question for me is purely about how we present the setting to users.

I think something we need to be very clear about is that the config location must be a directory, and we will unconditionally load init.lua from that directory. I think it would be a big mistake to let people point at arbitrary files, simply because then the search path stuff gets increasingly weird, and might interact with other files unintentionally.

So, I'd be ok with it hiding as an advanced option in our Info.plist, but I'd also be ok with there being a button in the Prefs window to select a directory to load the config from.

@cmsj, see pull #582 -- Since the definition of MJConfigFile in the source is for the full path to the init.lua file, and then is broken into path/file as needed, I stuck with that format. How you want this documented or if you want a preferences panel option, etc. to select this is up to you -- I'm ok with it being a setting which is adjusted via defaults or hs.settings and sticking it in the wiki/faq.

We'll leave it as an advanced defaults option for now, and if the request keeps coming, we can add GUI for it.
@nfarrar you'll be able to change the directory in the next release, which I hope will be out in the next day or so :)

@cmsj Was the possibility of changing config file location ever included?

I tried assigning to my custom folder but didn't succeed in importing the configurations from: /Users/me/Dropbox/hammerspoon/init.lua

These are the contents in ~/.hammerspoon/init.lua

package.path = os.getenv("HOME").."/Users/me/Dropbox/hammerspoon/?.lua;"..os.getenv("HOME").."/Users/me/Dropbox/hammerspoon/?/init.lua;"..package.path
package.cpath = os.getenv("HOME").."/Users/me/Dropbox/hammerspoon/?.so;"..package.cpath
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lazandrei19 picture lazandrei19  Â·  4Comments

agzam picture agzam  Â·  3Comments

tomrbowden picture tomrbowden  Â·  3Comments

franzwr picture franzwr  Â·  3Comments

luckman212 picture luckman212  Â·  4Comments