-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
981 additions
and
1,016 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- Credit for this implementation goes to @arbelt and @jasoncodes 🙇⚡️😻 | ||
-- | ||
-- https://gist.github.com/arbelt/b91e1f38a0880afb316dd5b5732759f1 | ||
-- https://github.com/jasoncodes/dotfiles/blob/ac9f3ac/hammerspoon/control_escape.lua | ||
|
||
send_escape = false | ||
last_mods = {} | ||
|
||
control_key_handler = function() | ||
send_escape = false | ||
end | ||
|
||
control_key_timer = hs.timer.delayed.new(0.15, control_key_handler) | ||
|
||
control_handler = function(evt) | ||
local new_mods = evt:getFlags() | ||
if last_mods["ctrl"] == new_mods["ctrl"] then | ||
return false | ||
end | ||
if not last_mods["ctrl"] then | ||
last_mods = new_mods | ||
send_escape = true | ||
control_key_timer:start() | ||
else | ||
if send_escape then | ||
keyUpDown({}, 'escape') | ||
end | ||
last_mods = new_mods | ||
control_key_timer:stop() | ||
end | ||
return false | ||
end | ||
|
||
control_tap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged}, control_handler) | ||
control_tap:start() | ||
|
||
other_handler = function(evt) | ||
send_escape = false | ||
return false | ||
end | ||
|
||
other_tap = hs.eventtap.new({hs.eventtap.event.types.keyDown}, other_handler) | ||
other_tap:start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
local log = hs.logger.new('delete-words.lua', 'debug') | ||
|
||
local isInTerminal = function() | ||
app = hs.application.frontmostApplication():name() | ||
return app == 'iTerm2' or app == 'Terminal' | ||
end | ||
|
||
-- Use option + h to delete previous word | ||
hs.hotkey.bind({'alt'}, 'h', function() | ||
if isInTerminal() then | ||
keyUpDown({'ctrl'}, 'w') | ||
else | ||
keyUpDown({'alt'}, 'delete') | ||
end | ||
end) | ||
|
||
-- Use option + l to delete next word | ||
hs.hotkey.bind({'alt'}, 'l', function() | ||
if isInTerminal() then | ||
keyUpDown({}, 'escape') | ||
keyUpDown({}, 'd') | ||
else | ||
keyUpDown({'alt'}, 'forwarddelete') | ||
end | ||
end) | ||
|
||
-- Use control + u to delete to beginning of line | ||
-- | ||
-- In bash, control + u automatically deletes to the beginning of the line, so | ||
-- we don't need (or want) this hotkey in the terminal. If this hotkey was | ||
-- enabled in the terminal, it would break the standard control + u behavior. | ||
-- Therefore, we only enable this hotkey for non-terminal apps. | ||
local wf = hs.window.filter.new():setFilters({iTerm2 = false, Terminal = false}) | ||
enableHotkeyForWindowsMatchingFilter(wf, hs.hotkey.new({'ctrl'}, 'u', function() | ||
keyUpDown({'cmd'}, 'delete') | ||
end)) | ||
|
||
-- Use control + ; to delete to end of line | ||
-- | ||
-- I prefer to use control+h/j/k/l to move left/down/up/right by one pane in all | ||
-- multi-pane apps (e.g., iTerm, various editors). That's convenient and | ||
-- consistent, but it conflicts with the default macOS binding for deleting to | ||
-- the end of the line (i.e., control+k). To maintain that very useful | ||
-- functionality, and to keep it on the home row, this hotkey binds control+; to | ||
-- delete to the end of the line. | ||
hs.hotkey.bind({'ctrl'}, ';', function() | ||
-- If we're in the terminal, then temporarily disable our custom control+k | ||
-- hotkey used for pane navigation, then fire control+k to delete to the end | ||
-- of the line, and then renable the control+k hotkey. | ||
-- | ||
-- If we're not in the terminal, then just select to the end of the line and | ||
-- then delete the selected text. | ||
if isInTerminal() then | ||
hotkeyForControlK = hs.fnutils.find(hs.hotkey.getHotkeys(), function(hotkey) | ||
return hotkey.idx == '⌃K' | ||
end) | ||
if hotkeyForControlK then hotkeyForControlK:disable() end | ||
|
||
keyUpDown({'ctrl'}, 'k') | ||
|
||
-- Allow some time for the control+k keystroke to fire asynchronously before | ||
-- we re-enable our custom control+k hotkey. | ||
hs.timer.doAfter(0.2, function() | ||
if hotkeyForControlK then hotkeyForControlK:enable() end | ||
end) | ||
else | ||
keyUpDown({'cmd', 'shift'}, 'right') | ||
keyUpDown({}, 'forwarddelete') | ||
end | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-- A global variable for Hyper Mode | ||
hyperMode = hs.hotkey.modal.new({}, 'F18') | ||
|
||
-- Keybindings for launching apps in Hyper Mode | ||
hyperModeAppMappings = { | ||
{ 'a', 'iTunes' }, -- "A" for "Apple Music" | ||
{ 'b', 'Google Chrome' }, -- "B" for "Browser" | ||
{ 'c', 'Hackable Slack Client' }, -- "C for "Chat" | ||
{ 'd', 'Remember The Milk' }, -- "D" for "Do!" ... or "Done!" | ||
{ 'e', 'Atom Beta' }, -- "E" for "Editor" | ||
{ 'f', 'Finder' }, -- "F" for "Finder" | ||
{ 'g', 'Mailplane 3' }, -- "G" for "Gmail" | ||
{ 't', 'iTerm' }, -- "T" for "Terminal" | ||
} | ||
|
||
for i, mapping in ipairs(hyperModeAppMappings) do | ||
hyperMode:bind({}, mapping[1], function() | ||
hs.application.launchOrFocus(mapping[2]) | ||
end) | ||
end | ||
|
||
-- Enter Hyper Mode when F17 (right option key) is pressed | ||
pressedF17 = function() | ||
hyperMode:enter() | ||
end | ||
|
||
-- Leave Hyper Mode when F17 (right option key) is released. | ||
releasedF17 = function() | ||
hyperMode:exit() | ||
end | ||
|
||
-- Bind the Hyper key | ||
f17 = hs.hotkey.bind({}, 'F17', pressedF17, releasedF17) |
Oops, something went wrong.