Skip to content

Instantly share code, notes, and snippets.

@rednebmas
Created November 5, 2017 05:03
Show Gist options
  • Select an option

  • Save rednebmas/1698c622c6d0a28a82e73c2d32177ad3 to your computer and use it in GitHub Desktop.

Select an option

Save rednebmas/1698c622c6d0a28a82e73c2d32177ad3 to your computer and use it in GitHub Desktop.
Hammerspoon config file
local function pressFn(mods, key)
if key == nil then
key = mods
mods = {}
end
return function() hs.eventtap.keyStroke(mods, key, 10) end
end
local function remap(mods, key, pressFn)
hs.hotkey.bind(mods, key, pressFn, nil, pressFn)
end
local function remap_unbound(mods, key, pressFn)
return hs.hotkey.new(mods, key, pressFn, nil, pressFn)
end
-- Move
remap({'ctrl'}, 'h', pressFn('left'))
remap({'ctrl'}, 'j', pressFn('down'))
remap({'ctrl'}, 'k', pressFn('up'))
remap({'ctrl'}, 'l', pressFn('right'))
-- Select and move
remap({'ctrl', 'shift'}, 'h', pressFn({'shift'}, 'left'))
remap({'ctrl', 'shift'}, 'j', pressFn({'shift'}, 'down'))
remap({'ctrl', 'shift'}, 'k', pressFn({'shift'}, 'up'))
remap({'ctrl', 'shift'}, 'l', pressFn({'shift'}, 'right'))
-- Jump by word move
remap({'alt'}, 'h', pressFn({'alt'}, 'left'))
remap({'alt'}, 'l', pressFn({'alt'}, 'right'))
-- Jump by word select
remap({'alt', 'shift'}, 'h', pressFn({'alt', 'shift'}, 'left'))
remap({'alt', 'shift'}, 'l', pressFn({'alt', 'shift'}, 'right'))
-- Jump to beginning/end of line/document
-- remap({'cmd'}, 'h', pressFn({'cmd'}, 'left'))
-- remap({'cmd'}, 'j', pressFn({'cmd'}, 'down'))
-- remap({'cmd'}, 'k', pressFn({'cmd'}, 'up'))
-- remap({'cmd'}, 'l', pressFn({'cmd'}, 'right'))
-- Select to beginning/end of line/document
-- remap({'shift', 'cmd'}, 'h', pressFn({'shift', 'cmd'}, 'left'))
-- remap({'shift', 'cmd'}, 'j', pressFn({'shift', 'cmd'}, 'down'))
-- remap({'shift', 'cmd'}, 'k', pressFn({'shift', 'cmd'}, 'up'))
-- remap({'shift', 'cmd'}, 'l', pressFn({'shift', 'cmd'}, 'right'))
--
-- Switch tab hotkeys
--
-- right
hs.hotkey.bind({'cmd', 'shift'}, 'l', function()
if hs.application.frontmostApplication():title() == 'Xcode' then
pressFn({'cmd', 'shift'}, ']')()
elseif hs.application.frontmostApplication():title() == 'Terminal' then
pressFn({'cmd', 'shift'}, ']')()
elseif hs.application.frontmostApplication():title() == 'Google Chrome' then
pressFn({'cmd', 'option'}, 'right')()
elseif hs.application.frontmostApplication():title() == 'AppCode' then
pressFn({'cmd', 'shift'}, ']')()
elseif hs.application.frontmostApplication():title() == 'Code' then
pressFn({'cmd', 'shift'}, ']')()
else
pressFn({'cmd', 'shift'}, 'l')()
end
end)
hs.hotkey.bind({'cmd', 'shift'}, 'h', function()
if hs.application.frontmostApplication():title() == 'Xcode' then
pressFn({'cmd', 'shift'}, '[')()
elseif hs.application.frontmostApplication():title() == 'Terminal' then
pressFn({'cmd', 'shift'}, '[')()
elseif hs.application.frontmostApplication():title() == 'Google Chrome' then
pressFn({'cmd', 'option'}, 'left')()
elseif hs.application.frontmostApplication():title() == 'AppCode' then
pressFn({'cmd', 'shift'}, '[')()
elseif hs.application.frontmostApplication():title() == 'Code' then
pressFn({'cmd', 'shift'}, '[')()
else
hs.alert.show('Should have passed through?')
hs.timer.doAfter(1000, function() pressFn({'cmd', 'shift'}, 'h')() end)
end
end)
runInXcodeFromMacVim = hs.hotkey.new('⌘', 'r', function()
hs.alert.show("Run in Xcode")
hs.application.launchOrFocus("Xcode.app")
hs.eventtap.keyStroke({'⌘'}, 'r')
hs.application.launchOrFocus("MacVim.app")
end)
hs.window.filter.new('MacVim')
:subscribe(hs.window.filter.windowFocused,function() runInXcodeFromMacVim:enable() end)
:subscribe(hs.window.filter.windowUnfocused,function() runInXcodeFromMacVim:disable() end)
switchToImpHeader = hs.hotkey.new('⌘', 'j', function()
-- hs.alert.show("Switch")
hs.application.get('Xcode'):selectMenuItem('Jump to Next Counterpart')
end)
hs.window.filter.new('Xcode')
:subscribe(hs.window.filter.windowFocused,function() switchToImpHeader:enable() end)
:subscribe(hs.window.filter.windowUnfocused,function() switchToImpHeader:disable() end)
--
-- reload hammerspoon config
--
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
hs.reload()
end)
hs.alert.show("Config loaded")
-- misc
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "I", function()
hs.alert.show(hs.application.frontmostApplication():title())
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment