Skip to content

Commit

Permalink
feat(hs): add hammerspoon configs
Browse files Browse the repository at this point in the history
  • Loading branch information
silveiralexf committed Jul 21, 2024
1 parent 5e00344 commit 0dd99ff
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ package-lock.json

# BFG
..bfg-report/

# Hammerspoon Spoons
hammerspoon/Spoons/
6 changes: 4 additions & 2 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"diagnostics.globals": [
"vim",
"args"
"args",
"hs",
"spoon"
]
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@


### [2024-07-18]
* [[5e00344]](https://github.com/silveiralexf/.dotfiles/commit/5e003444120f2dd3e2fc9d16058c068f33d19967) chore(nvim): link go src to git to avoid duplicates (silveiralexf@gmail.com)


* [[cf2255d]](https://github.com/silveiralexf/.dotfiles/commit/cf2255d5651968efc872ba8122fcd111bd8165c5) chore(docs): add wakatime badge to readme (silveiralexf@gmail.com)


Expand Down
2 changes: 2 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ includes:
taskfile: ./tasks/macos/install/python/Taskfile.yml
macos:install:rust:
taskfile: ./tasks/macos/install/rust/Taskfile.yml
macos:install:hammerspoon:
taskfile: ./tasks/macos/install/hammerspoon/Taskfile.yml
tasks:
default:
cmds:
Expand Down
100 changes: 100 additions & 0 deletions hammerspoon/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
-- Config reload
hs.hotkey.bind({ "cmd", "alt", "ctrl" }, "R", function()
hs.reload()
end)
hs.alert.show("Hammerspoon re-loaded")

-- Load & initialize Ki spoon
hs.loadSpoon("Ki")

-- Set state events to enable transitions for scroll mode.
-- Expose `enterScrollMode` in the FSM to allow transition from normal mode to scroll mode,
-- and `exitMode` to exit from scroll mode back to desktop mode.
spoon.Ki.stateEvents = {
{ name = "enterScrollMode", from = "normal", to = "scroll" },
{ name = "exitMode", from = "scroll", to = "desktop" },
}

-- Set custom scroll mode transition events.
spoon.Ki.transitionEvents = {
-- Add normal mode transition event to enter scroll mode with cmd+ctrl+s from normal mode
normal = {
{
{ "cmd", "alt", "ctrl" },
"s",
function()
spoon.Ki.state:enterScrollMode()
end,
{ "Normal Mode", "Transition to Scroll Mode" },
},
},
-- Add scroll mode transition event to exit scroll mode with escape back to desktop mode.
scroll = {
{
nil,
"escape",
function()
spoon.Ki.state:exitMode()
end,
{ "Scroll Mode", "Exit to Desktop Mode" },
},
},
}

-- Scroll event handler helper method
local function createScrollEvent(offsets)
return function()
hs.eventtap.event.newScrollEvent(offsets, {}, "pixel"):post()
end
end

-- Define custom scroll mode shortcuts
local scrollEvents = {
{ nil, "h", createScrollEvent({ 50, 0 }), { "Scroll Events", "Scroll Left" } },
{ nil, "k", createScrollEvent({ 0, 50 }), { "Scroll Events", "Scroll Up" } },
{ nil, "j", createScrollEvent({ 0, -50 }), { "Scroll Events", "Scroll Down" } },
{ nil, "l", createScrollEvent({ -50, 0 }), { "Scroll Events", "Scroll Right" } },
{ { "ctrl" }, "d", createScrollEvent({ 0, -500 }), { "Scroll Events", "Scroll Half Page Down" } },
{ { "ctrl" }, "u", createScrollEvent({ 0, 500 }), { "Scroll Events", "Scroll Half Page Up" } },
}

-- Set custom workflows
spoon.Ki.workflowEvents = {
scroll = scrollEvents,
}

-- Start Ki Spoon
spoon.Ki:start()

--------------------------------
-- START VIM CONFIG
--------------------------------
local VimMode = hs.loadSpoon("VimMode")
local vim = VimMode:new()

-- Configure apps you do *not* want Vim mode enabled in
vim:disableForApp("Code")
:disableForApp("zoom.us")
:disableForApp("iTerm")
:disableForApp("iTerm2")
:disableForApp("Terminal")
:disableForApp("Kitty")
:disableForApp("kitty")

-- If you want the screen to dim (a la Flux) when you enter normal mode
-- flip this to true.
vim:shouldDimScreenInNormalMode(false)

-- If you want to show an on-screen alert when you enter normal mode, set
-- this to true
vim:shouldShowAlertInNormalMode(true)

-- You can configure your on-screen alert font
vim:setAlertFont("Courier New")

-- Enter normal mode by typing a key sequence
vim:enterWithSequence("jk")

--------------------------------
-- END VIM CONFIG
--------------------------------
14 changes: 14 additions & 0 deletions tasks/macos/install/hammerspoon/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3"
tasks:
all:
desc: Install Hammerspoon's plugins
cmds:
- task: all:spoons
all:spoons:
desc: Install Spoons
status:
- test -d ~/.dotfiles/hammerspoon/Spoons/Ki.spoon
- test -d ~/.dotfiles/hammerspoon/Spoons/VimMode.spoon
- test -d ~/.dotfiles/hammerspoon/Spoons/SpoonInstall.spoon
cmds:
- bash <(curl -s https://raw.githubusercontent.com/dbalatero/VimMode.spoon/master/bin/installer)

0 comments on commit 0dd99ff

Please sign in to comment.