Skip to content

Instantly share code, notes, and snippets.

@refnode
Created March 11, 2023 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refnode/c6899b5577d86d4bf80c8e01be760e2d to your computer and use it in GitHub Desktop.
Save refnode/c6899b5577d86d4bf80c8e01be760e2d to your computer and use it in GitHub Desktop.
Hammerspoon Config
-- ~/.config/hammerspoon/init.lua
--
----------------------------------------------------------------------
-- Hammerspoon configuration file
----------------------------------------------------------------------
-- Enable ICP and install the Hammerspoon cli "hs" to /usr/local/bin
require("hs.ipc")
hs.ipc.cliInstall()
hs.dockicon.hide()
-- Create a new hammerspoon pathwatcher for the hammerspoon configuration dir
-- usually $HOME/.hammerspoon and call hammerspoon reload on changes
function check_and_reload(paths, flagTables)
for k, v in pairs(paths) do
local url_parts = hs.http.urlParts(v)
if url_parts["pathExtension"] == "lua" then
print("Lua file change detected: " .. v)
print("Reloading Hammerspoon")
hs.reload()
end
end
end
hs.pathwatcher.new(hs.configdir, check_and_reload):start()
----------------------------------------------------------------------
-- === global configuration ===
----------------------------------------------------------------------
-- keyboard shortcuts
hyper = {"cmd","alt","ctrl"}
----------------------------------------------------------------------
-- app config
function getBundleID(app)
return hs.application.infoForBundlePath(app)['CFBundleIdentifier']
end
local appHotKeys = {
s = "Alacritty.app",
w = "Vivaldi.app",
v = "music.app",
}
local launchOrFocus = function(appName)
return function()
hs.application.launchOrFocus(appName)
end
end
for key, app in pairs(appHotKeys) do
hs.hotkey.bind(hyper, key, launchOrFocus(app))
end
function window_minimize()
local window = hs.window.focusedWindow()
window:minimize()
end
hs.hotkey.bind(hyper, "-", function()
hs.reload()
hs.notify.new({title="Hammerspoon", informativeText="Configuration reloaded"}):send()
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment