Skip to content

Commit

Permalink
CONF: Try adding key config on darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoZeke committed Jan 8, 2022
1 parent 3e461e8 commit 9aa9a48
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .chezmoiignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{ if ne .chezmoi.os "darwin" }}
encrypted_chezmoi_darwin.toml.asc
*hammerspoon
*karabiner
{{ end }}
{{ if ne .chezmoi.os "linux" }}
encrypted_chezmoi_toml_linux
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"title": "CAPS to fake hyper (f19) and Shift CAPS",
"rules": [
{
"description": "CAPS_LOCK : (HYPER)",
"manipulators": [
{
"from": {
"key_code": "caps_lock",
"modifiers": {
"optional": ["any"]
}
},
"to":
{
"key_code": "f19"
},
"type": "basic"
}
]
},
{
"description": "Toggle CAPS_LOCK with LEFT_SHIFT + RIGHT_SHIFT",
"manipulators": [
{
"from": {
"key_code": "left_shift",
"modifiers": {
"mandatory": ["right_shift"],
"optional": ["caps_lock"]
}
},
"to": [
{
"key_code": "caps_lock"
}
],
"to_if_alone": [
{
"key_code": "left_shift"
}
],
"type": "basic"
},
{
"from": {
"key_code": "right_shift",
"modifiers": {
"mandatory": ["left_shift"],
"optional": ["caps_lock"]
}
},
"to": [
{
"key_code": "caps_lock"
}
],
"to_if_alone": [
{
"key_code": "right_shift"
}
],
"type": "basic"
}
]
}
]
}
138 changes: 138 additions & 0 deletions dot_hammerspoon/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
-- Reload config when any lua file in config directory changes
-- From https://gist.github.com/prenagha/1c28f71cb4d52b3133a4bff1b3849c3e
function reloadConfig(files)
doReload = false
for _,file in pairs(files) do
if file:sub(-4) == '.lua' then
doReload = true
end
end
if doReload then
hs.reload()
end
end
local myWatcher = hs.pathwatcher.new(os.getenv('HOME') .. '/.hammerspoon/', reloadConfig):start()
hs.alert.show('Config loaded')

-- A global variable for the Hyper Mode
hyper = hs.hotkey.modal.new({}, 'F18')

-- Enter Hyper Mode when F19 (Hyper/Capslock) is pressed
function enterHyperMode()
hyper.triggered = false
hyper:enter()
end

-- Leave Hyper Mode when F19 (Hyper/Capslock) is pressed,
-- send ESCAPE if no other keys are pressed.
function exitHyperMode()
hyper:exit()
if not hyper.triggered then
-- local app = hs.application.frontmostApplication()
-- if app:name() == "Emacs" then
-- Do nothing
-- else
-- hs.eventtap.keyStroke({}, 'ESCAPE')
-- end
end
end

-- Bind the Hyper key
f19 = hs.hotkey.bind({}, 'F19', enterHyperMode, exitHyperMode)
f19cmd = hs.hotkey.bind({'cmd'}, 'F19', enterHyperMode, exitHyperMode)

-- Vim Colemak bindings (hzColemak)

-- Basic Movements {{{2

-- h - move left {{{3
function left() hs.eventtap.keyStroke({}, "Left", 0) end
hyper:bind({}, 'h', left, nil, left)
-- }}}3

-- n - move down {{{3
function down() hs.eventtap.keyStroke({}, "Down", 0) end
hyper:bind({}, 'n', down, nil, down)
-- }}}3

-- e - move up {{{3
function up() hs.eventtap.keyStroke({}, "Up", 0) end
hyper:bind({}, 'e', up, nil, up)
-- }}}3

-- i - move right {{{3
function right() hs.eventtap.keyStroke({}, "Right", 0) end
hyper:bind({}, 'i', right, nil, right)
-- }}}3

-- ) - right programming brace {{{3
function rbroundL() hs.eventtap.keyStrokes("(") end
hyper:bind({}, 'k', rbroundL, nil, rbroundL)
-- }}}3

-- ) - left programming brace {{{3
function rbroundR() hs.eventtap.keyStrokes(")") end
hyper:bind({}, 'v', rbroundR, nil, rbroundR)
-- }}}3

-- o - open new line below cursor {{{3
hyper:bind({}, 'o', nil, function()
local app = hs.application.frontmostApplication()
if app:name() == "Finder" then
hs.eventtap.keyStroke({"cmd"}, "o", 0)
else
hs.eventtap.keyStroke({}, "Return", 0)
end
end)
-- }}}3

-- Extend+AltGr layer
-- Delete {{{3

-- cmd+h - delete character before the cursor {{{3
local function delete()
hs.eventtap.keyStroke({}, "delete", 0)
end
hyper:bind({"cmd"}, 'h', delete, nil, delete)
-- }}}3

-- cmd+i - delete character after the cursor {{{3
local function fndelete()
hs.eventtap.keyStroke({}, "Right", 0)
hs.eventtap.keyStroke({}, "delete", 0)
end
hyper:bind({"cmd"}, 'i', fndelete, nil, fndelete)
-- }}}3

-- ) - right programming brace {{{3
function rbcurlyL() hs.eventtap.keyStrokes("{") end
hyper:bind({"cmd"}, 'k', rbcurlyL, nil, rbcurlyL)
-- }}}3

-- ) - left programming brace {{{3
function rbcurlyR() hs.eventtap.keyStrokes("}") end
hyper:bind({"cmd"}, 'v', rbcurlyR, nil, rbcurlyR)
-- }}}3

-- Extend+Shift

-- ) - right programming brace {{{3
function rbsqrL() hs.eventtap.keyStrokes("[") end
hyper:bind({"shift"}, 'k', rbsqrL, nil, rbsqrL)
-- }}}3

-- ) - left programming brace {{{3
function rbsqrR() hs.eventtap.keyStrokes("]") end
hyper:bind({"shift"}, 'v', rbsqrR, nil, rbsqrR)
-- }}}3

-- Special Movements
-- w - move to next word {{{3
function word() hs.eventtap.keyStroke({"alt"}, "Right", 0) end
hyper:bind({}, 'w', word, nil, word)
-- }}}3

-- b - move to previous word {{{3
function back() hs.eventtap.keyStroke({"alt"}, "Left", 0) end
hyper:bind({}, 'b', back, nil, back)
-- }}}3

0 comments on commit 9aa9a48

Please sign in to comment.