diff options
| author | Simen A. W. Olsen <so@bjerk.io> | 2024-05-17 10:05:29 +0200 |
|---|---|---|
| committer | Simen A. W. Olsen <so@bjerk.io> | 2024-05-17 10:05:29 +0200 |
| commit | a2f43302e1524cc8fe38791e0fdc00a3695fb76b (patch) | |
| tree | e393d1789a8d4a444d18425229f0f778ceb7342e /.hammerspoon/hyper.lua | |
| parent | e0b3900d8b50b499a5527e0f6d3590649fd4cefb (diff) | |
| download | dotfiles-a2f43302e1524cc8fe38791e0fdc00a3695fb76b.tar.gz dotfiles-a2f43302e1524cc8fe38791e0fdc00a3695fb76b.zip | |
updates
Diffstat (limited to '.hammerspoon/hyper.lua')
| -rw-r--r-- | .hammerspoon/hyper.lua | 91 |
1 files changed, 72 insertions, 19 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 + |
