-
Notifications
You must be signed in to change notification settings - Fork 594
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
hs.configdir resolution change in 0.9.79 breaks module loading for symlinked configs #2478
Comments
Re-tested with 0.9.80, just in case. Same problem. I found a simpler workaround though, adding these 2 lines at the top of hs.configdir = os.getenv('HOME') .. '/.hammerspoon'
package.path = hs.configdir .. '/?.lua;' .. hs.configdir .. '/?/init.lua;' .. hs.configdir .. '/Spoons/?.spoon/init.lua;' .. package.path (update: added I searched the source to try and find where |
I had the same problem since I use homeshick to manage my dotfiles in a git repo, and all of my dotfiles are symlinks. If you want Spoons to load, you'll need those in package.path as well: hs.configdir = os.getenv('HOME') .. '/.hammerspoon'
package.path = hs.configdir .. '/?.lua;' .. hs.configdir .. '/?/init.lua;' .. hs.configdir .. '/Spoons/?.spoon/init.lua;' .. package.path |
I would be curious if a brand new build of 0.9.78 with the current XCode (12, I believe) has the same issue because I don't believe that the relevant code in |
Ironically, I think @luckman212's fix for another problem actually introduced this particular issue? @asmagill & @cmsj - I think the problem was introduced here: #2359 Specifically I'm not sure of the best solution to fix? |
Regarding:
local modpath, prettypath, fullpath, configdir, docstringspath, hasinitfile, autoload_extensions = ...
package.path=configdir.."/?.lua"..";"..configdir.."/?/init.lua"..";"..configdir.."/Spoons/?.spoon/init.lua"..";"..package.path..";"..modpath.."/?.lua"..";"..modpath.."/?/init.lua"
package.cpath=configdir.."/?.so"..";"..package.cpath..";"..modpath.."/?.so" The lua_pushstring(L, [MJConfigDir() UTF8String]); ...and #import "MJConfigUtils.h"
#import "variables.h"
NSString* MJConfigDir(void) {
return [MJConfigFileFullPath() stringByDeletingLastPathComponent];
}
NSString* MJConfigFileFullPath(void) {
return [[MJConfigFile stringByStandardizingPath] stringByResolvingSymlinksInPath];
} As explained in my last post, When I'm running Hammerspoon 0.9.80 (5530) I get: > hs.configdir
/Users/chrishocking/.hammerspoon
> os.getenv('HOME') .. '/.hammerspoon'
/Users/chrishocking/.hammerspoon
> package.path
/Users/chrishocking/.hammerspoon/?.lua;/Users/chrishocking/.hammerspoon/?/init.lua;/Users/chrishocking/.hammerspoon/Spoons/?.spoon/init.lua;/usr/local/share/lua/5.4/?.lua;/usr/local/share/lua/5.4/?/init.lua;/usr/local/lib/lua/5.4/?.lua;/usr/local/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua;/Applications/Hammerspoon.app/Contents/Resources/extensions/?.lua;/Applications/Hammerspoon.app/Contents/Resources/extensions/?/init.lua
> package.cpath
/Users/chrishocking/.hammerspoon/?.so;/usr/local/lib/lua/5.4/?.so;/usr/local/lib/lua/5.4/loadall.so;./?.so;/Applications/Hammerspoon.app/Contents/Resources/extensions/?.so When I'm running Hammerspoon 0.9.78 (5164) I get: > hs.configdir
/Users/chrishocking/.hammerspoon
> os.getenv('HOME') .. '/.hammerspoon'
/Users/chrishocking/.hammerspoon
> package.path
/Users/chrishocking/.hammerspoon/?.lua;/Users/chrishocking/.hammerspoon/?/init.lua;/Users/chrishocking/.hammerspoon/Spoons/?.spoon/init.lua;/usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua;/private/var/folders/tp/p7td6g9x28d425wct7ryyr_40000gn/T/AppTranslocation/71EAE9DB-CE95-4F94-9871-F1B9C09BCB76/d/Hammerspoon.app/Contents/Resources/extensions/?.lua;/private/var/folders/tp/p7td6g9x28d425wct7ryyr_40000gn/T/AppTranslocation/71EAE9DB-CE95-4F94-9871-F1B9C09BCB76/d/Hammerspoon.app/Contents/Resources/extensions/?/init.lua
> package.cpath
/Users/chrishocking/.hammerspoon/?.so;/usr/local/lib/lua/5.3/?.so;/usr/local/lib/lua/5.3/loadall.so;./?.so;/private/var/folders/tp/p7td6g9x28d425wct7ryyr_40000gn/T/AppTranslocation/71EAE9DB-CE95-4F94-9871-F1B9C09BCB76/d/Hammerspoon.app/Contents/Resources/extensions/?.so ...so these changes don't affect most users, but if you're sym-linking your I'm not sure what the right fix is though? |
@latenitefilms you are absolutely correct -- missed that line as it's in As #2359 was introduced to help with Spoon installation, the only real fix to regain past behavior of That is if we're certain that:
|
We probably don't need to alter |
I use This would be in line with the shell command |
FWIW, I think I prefer |
For example: NSString *configDir = MJConfigDir();
NSString *spoonPath = [[[configDir stringByStandardizingPath] stringByResolvingSymlinksInPath] stringByAppendingPathComponent:@"Spoons"]; |
$ egrep -n 'MJConfig\w+\(' MJAppDelegate.m
52: NSString *spoonPath = [MJConfigDir() stringByAppendingPathComponent:@"Spoons"];
57: NSLog(@"User double clicked on a Spoon in %@, skipping", MJConfigDir());
191: NSString *spoonsPath = [MJConfigDir() stringByAppendingPathComponent:@"Spoons"];
212: MJEnsureDirectoryExists(MJConfigDir());
213: [[NSFileManager defaultManager] changeCurrentDirectoryPath:MJConfigDir()];
333: NSString* path = MJConfigFileFullPath(); Looks like a couple of more places you might need to consider (not sure that all of them matter as much, but they should all be looked at closely to make sure), but still doable... Does one of the additions you've made recently to |
(I did just notice that typo too!) I guess there's no harm in adding I'll leave this to you, unless you want me to tackle later today. |
Yes, that functions does what I would need: > hs.configdir .. "/Spoons"
/Users/xxxxx/.config/hammerspoon/Spoons
> hs.fs.pathToAbsolute(hs.configdir .. "/Spoons")
/opt/xxxxx/src/hammerspoon/Spoons/Source My Spoons directory is a symlink into the source folder of the repository to make it easier to keep a current full set -- I haven't run into the issue with double clicking on them because I already have all of the standard ones, and I manually move any others into No specific need for So is the consensus to revert I can try to work up a pull tomorrow unless you want to do so sooner, either way is fine with me. |
@asmagill & @luckman212 - I've pushed a fix in #2490, which I'm hoping solves both this issue (#2478), and the original #2357 issue. Any questions let me know. |
Automatically closed when pull merged; reopen if you still have an issue after trying a build off of master branch. |
Thanks @asmagill, @cmsj, @latenitefilms β and to everyone else who contributed to this new release! π
I've been keeping my configs in sync between multiple Macs by symlinking
init.lua
(and other modules) into~/.hammerspoon
from a central config dir (~/Sync/Settings/Hammerpoon
) using Resilio Sync.My config failed to load when upgrading from 0.9.78. In the console, the following errors were logged:
I eventually figured out that this was due to a change in the way
hs.configdir
is resolved. Previously, it seems like it would resolve to~/.hammerspoon
but now, ifinit.lua
is itself a symlink, thenhs.configdir
is set to the parent directory of the absolute path of the real file. This is probably fine for 99.9% of usersβ but in my case, it broke my configuration.I have the following symlinks:
The reason I do this is so I can share chunks of configuration in
init.lua
between multiple Macs, but have the keybinds/module settings be specific to the machine that's loading them. I symlink a custom file for each machine but they are all named e.g. "keybinds.lua".I "fixed" it by adding a function to my
init.lua
:This has gotten things working again for me. But I'm guessing there's a cleaner way to handle this...?
The text was updated successfully, but these errors were encountered: