Skip to content

Instantly share code, notes, and snippets.

@rkoch
Created October 7, 2018 15:41
Show Gist options
  • Save rkoch/ff989634cf5352ec87f37649fcb053c9 to your computer and use it in GitHub Desktop.
Save rkoch/ff989634cf5352ec87f37649fcb053c9 to your computer and use it in GitHub Desktop.
Hammerspoon Auto Reload Config
#!/usr/bin/env bash
log () {
echo "LOG[hammerspoon]: $1"
}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DEFAULTS=/usr/bin/defaults
BUDDY=/usr/libexec/PlistBuddy
DOMAIN="org.hammerspoon.Hammerspoon"
log 'Starting and stopping Hammerspoon for initial preferences.'
open /Applications/Hammerspoon.app
sleep 2
killall Hammerspoon
sleep 2
log 'Updating default settings'
$DEFAULTS write $DOMAIN MJConfigFile "~/.config/hammerspoon/init.lua"
$DEFAULTS write $DOMAIN MJShowDockIconKey -bool false
$DEFAULTS write $DOMAIN MJShowMenuIconKey -bool false
$DEFAULTS write $DOMAIN MJSkipDockMenuIconProblemAlertKey -bool true
log 'Linking configuration'
ln -s $DIR ~/.config/hammerspoon
-- Toogle Emacs window using alt-e
local function togglEmacs()
local e = hs.application.get('Emacs')
if e then
if e:isFrontmost() then
e:hide()
else
e:activate()
end
end
end
hs.hotkey.bind({"alt"}, "e", togglEmacs)
-- lol
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
hs.notify.new({title="Hammerspoon", informativeText="Hello World"}):send()
end)
-- Reload config automatically
local configFileWatcher
function reloadConfig()
configFileWatcher:stop()
configFileWatcher = nil
hs.reload()
end
configFileWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.config/hammerspoon/", reloadConfig)
configFileWatcher:start()
-- Load local modules
require("hello-world")
require("emacs")
-- Load Spoons
--
-- Finally, show a notification that we finished loading the config
hs.notify.new( {title='Hammerspoon', subTitle='Configuration loaded'} ):send()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment