aboutsummaryrefslogtreecommitdiffstats
path: root/.hammerspoon
diff options
context:
space:
mode:
Diffstat (limited to '.hammerspoon')
-rw-r--r--.hammerspoon/hyper.lua91
-rw-r--r--.hammerspoon/init.lua48
2 files changed, 112 insertions, 27 deletions
diff --git a/.hammerspoon/hyper.lua b/.hammerspoon/hyper.lua
index 4cca4db..e5380f9 100644
--- a/.hammerspoon/hyper.lua
+++ b/.hammerspoon/hyper.lua
@@ -1,27 +1,80 @@
-local hyper = hs.hotkey.modal.new({}, nil)
+local This = {}
-hyper.pressed = function()
- hyper:enter()
-end
-hyper.released = function()
- hyper:exit()
-end
+-----------------------------------------------------------------------------------
+-- File: hyper.lua
+-- Author: J.H. Kuperus
+-- Source: https://github.com/jhkuperus/dotfiles/blob/master/hammerspoon/hyper.lua
+-- "License": Feel free to use this file any way you like. Issues or improvements
+-- are welcome on the GitHub repository. No warranties whatsoever.
+-----------------------------------------------------------------------------------
+
+-- To use Hyper in your init.lua script, import it and adapt this example to
+-- your needs:
+--
+-- local hyper = require('hyper')
+-- hyper.install('F18')
+-- hyper.bindkey('r', hs.reload)
+--
+-- The above three lines initialize Hyper to respond to F18 key-events and binds
+-- Hyper+r to Hammerspoon Reload (easy way to refresh Hammerspoon's config)
-- Hyper mode needs to be bound to a key. Here we are binding
-- it to F17, because this is yet another key that's unused.
-- Why not F18? We will use key-events from F18 to turn hyper
--- mode on and off. Using F17 as both the modal and source of key
--- events will result in a very jittery Hyper mode.
-hs.hotkey.bind({}, "F18", hyper.pressed, hyper.released)
+-- mode on and off. Using F17 as the modal and source of key
+-- events, will result in a very jittery Hyper mode.
-hyper.bindApp = function(mods, key, app)
- local fn = function()
- hs.application.launchOrFocus(app)
- end
- if type(app) == "function" then
- fn = app
- end
- hyper:bind(mods, key, fn)
+This.hyperMode = hs.hotkey.modal.new({}, "F17")
+
+-- Enter Hyper Mode when F18 (Hyper) is pressed
+function enterHyperMode()
+ This.hyperMode:enter()
end
-return hyper
+-- Leave Hyper Mode when F18 (Hyper) is pressed
+function exitHyperMode()
+ This.hyperMode:exit()
+end
+
+-- Utility to bind handler to Hyper+key
+function This.bindKey(key, handler)
+ This.hyperMode:bind({}, key, handler)
+end
+
+-- Utility to bind handler to Hyper+Shift+key
+function This.bindShiftKey(key, handler)
+ This.hyperMode:bind({ "shift" }, key, handler)
+end
+
+-- Utility to bind handler to Hyper+Command+Shift+key
+function This.bindCommandShiftKey(key, handler)
+ This.hyperMode:bind({ "command", "shift" }, key, handler)
+end
+
+-- Utility to bind handler to Hyper+modifiers+key
+function This.bindKeyWithModifiers(key, mods, handler)
+ This.hyperMode:bind(mods, key, handler)
+end
+
+-- Binds the enter/exit functions of the Hyper modal to all combinations of modifiers
+function This.install(hotKey)
+ hs.hotkey.bind({}, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "shift" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "ctrl" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "ctrl", "shift" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "cmd" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "cmd", "shift" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "cmd", "ctrl" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "cmd", "ctrl", "shift" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "alt" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "alt", "shift" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "alt", "ctrl" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "alt", "ctrl", "shift" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "alt", "cmd" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "alt", "cmd", "shift" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "alt", "cmd", "ctrl" }, hotKey, enterHyperMode, exitHyperMode)
+ hs.hotkey.bind({ "alt", "cmd", "shift", "ctrl" }, hotKey, enterHyperMode, exitHyperMode)
+end
+
+return This
+
diff --git a/.hammerspoon/init.lua b/.hammerspoon/init.lua
index f4ee5d1..234f316 100644
--- a/.hammerspoon/init.lua
+++ b/.hammerspoon/init.lua
@@ -1,10 +1,42 @@
local hyper = require("hyper")
+hyper.install("F18")
-hyper.bindApp({}, "a", "Arc")
-hyper.bindApp({}, "w", "Warp")
-hyper.bindApp({}, "s", "Slack")
-hyper.bindApp({}, "1", "1Password")
-hyper.bindApp({}, "r", "Rize")
-hyper.bindApp({}, "d", "Obsidian")
-hyper.bindApp({}, "c", "Google Chrome")
-hyper.bindApp({}, "t", "Notification Center")
+hyper.bindKey("a", function()
+ hs.application.launchOrFocus("Arc")
+end)
+
+hyper.bindKey("w", function()
+ hs.application.launchOrFocus("Warp")
+end)
+
+hyper.bindKey("e", function()
+ hs.application.launchOrFocus("iTerm")
+end)
+
+hyper.bindKey("s", function()
+ hs.application.launchOrFocus("Slack")
+end)
+
+hyper.bindKey("1", function()
+ hs.application.launchOrFocus("1Password")
+end)
+
+hyper.bindKey("r", function()
+ hs.application.launchOrFocus("Rize")
+end)
+
+hyper.bindKey("d", function()
+ hs.application.launchOrFocus("Obsidian")
+end)
+
+hyper.bindKey("c", function()
+ hs.application.launchOrFocus("Google Chrome")
+end)
+
+hyper.bindKey("t", function()
+ hs.application.launchOrFocus("Notification Center")
+end)
+
+hyper.bindKey("m", function()
+ hs.application.launchOrFocus("Messages")
+end)