Files
dotfiles/hammerspoon/.hammerspoon/init.lua

349 lines
8.5 KiB
Lua

--------------------------------------------------------------------------
hyperModeAppMappings = {
{ 'a', 'Alacritty' }, -- "A" for "Apple Music"
{ 's', 'Safari' }, -- "S" for "Safari"
{ 'c', 'Telegram' }, -- "C for "Chat"
{ 'd', 'Discord' }, -- "D for "Discord"
{ 'f', 'Finder' }, -- "F" for "Finder"
{ 'g', 'Mail' }, -- "G" for "Gmail"
{ 'z', 'Slack' }, -- "Z" for "zzz"
{ 'n', 'Notion' }, -- "N" for "Notion"
{ 'm', 'Music' }, -- "M" for "Music"
{ 'w', 'World of Warcraft Classic' }, -- "W" for "World of Warcraft"
}
for i, mapping in ipairs(hyperModeAppMappings) do
local key = mapping[1]
local app = mapping[2]
hs.hotkey.bind({'shift', 'ctrl', 'alt', 'cmd'}, key, function()
if (type(app) == 'string') then
hs.application.open(app)
elseif (type(app) == 'function') then
app()
else
hs.logger.new('hyper'):e('Invalid mapping for Hyper +', key)
end
end)
end
--------------------------------------------------------------------------
hs.window.animationDuration = 0
window = hs.getObjectMetatable("hs.window")
-- +-----------------+
-- | | |
-- | HERE | |
-- | | |
-- +-----------------+
function window.left(win)
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end
-- +-----------------+
-- | | |
-- | | HERE |
-- | | |
-- +-----------------+
function window.right(win)
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end
-- +-----------------+
-- | HERE |
-- +-----------------+
-- | |
-- +-----------------+
function window.up(win)
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.w = max.w
f.y = max.y
f.h = max.h / 2
win:setFrame(f)
end
-- +-----------------+
-- | |
-- +-----------------+
-- | HERE |
-- +-----------------+
function window.down(win)
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.w = max.w
f.y = max.y + (max.h / 2)
f.h = max.h / 2
win:setFrame(f)
end
-- +-----------------+
-- | HERE | |
-- +--------+ |
-- | |
-- +-----------------+
function window.upLeft(win)
local f = win:frame()
local screen = win:screen()
local max = screen:fullFrame()
f.x = max.x
f.y = max.y
f.w = max.w/2
f.h = max.h/2
win:setFrame(f)
end
-- +-----------------+
-- | |
-- +--------+ |
-- | HERE | |
-- +-----------------+
function window.downLeft(win)
local f = win:frame()
local screen = win:screen()
local max = screen:fullFrame()
f.x = max.x
f.y = max.y + (max.h / 2)
f.w = max.w/2
f.h = max.h/2
win:setFrame(f)
end
-- +-----------------+
-- | |
-- | +--------|
-- | | HERE |
-- +-----------------+
function window.downRight(win)
local f = win:frame()
local screen = win:screen()
local max = screen:fullFrame()
f.x = max.x + (max.w / 2)
f.y = max.y + (max.h / 2)
f.w = max.w/2
f.h = max.h/2
win:setFrame(f)
end
-- +-----------------+
-- | | HERE |
-- | +--------|
-- | |
-- +-----------------+
function window.upRight(win)
local f = win:frame()
local screen = win:screen()
local max = screen:fullFrame()
f.x = max.x + (max.w / 2)
f.y = max.y
f.w = max.w/2
f.h = max.h/2
win:setFrame(f)
end
-- +--------------+
-- | | | |
-- | | HERE | |
-- | | | |
-- +---------------+
function window.centerWithFullHeight(win)
local f = win:frame()
local screen = win:screen()
local max = screen:fullFrame()
f.x = max.x + (max.w / 5)
f.w = max.w * 3/5
f.y = max.y
f.h = max.h
win:setFrame(f)
end
-- +-----------------+
-- | | |
-- | HERE | |
-- | | |
-- +-----------------+
function window.left40(win)
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w * 0.4
f.h = max.h
win:setFrame(f)
end
-- +-----------------+
-- | | |
-- | | HERE |
-- | | |
-- +-----------------+
function window.right60(win)
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w * 0.4)
f.y = max.y
f.w = max.w * 0.6
f.h = max.h
win:setFrame(f)
end
function window.nextScreen(win)
local currentScreen = win:screen()
local allScreens = hs.screen.allScreens()
currentScreenIndex = hs.fnutils.indexOf(allScreens, currentScreen)
nextScreenIndex = currentScreenIndex + 1
if allScreens[nextScreenIndex] then
win:moveToScreen(allScreens[nextScreenIndex])
else
win:moveToScreen(allScreens[1])
end
end
windowLayoutMode = hs.hotkey.modal.new({}, 'F16')
windowLayoutMode.entered = function()
windowLayoutMode.statusMessage:show()
end
windowLayoutMode.exited = function()
windowLayoutMode.statusMessage:hide()
end
-- Bind the given key to call the given function and exit WindowLayout mode
function windowLayoutMode.bindWithAutomaticExit(mode, modifiers, key, fn)
mode:bind(modifiers, key, function()
mode:exit()
fn()
end)
end
local status, windowMappings = pcall(require, 'keyboard.windows-bindings')
if not status then
windowMappings = require('keyboard.windows-bindings-defaults')
end
local modifiers = windowMappings.modifiers
local showHelp = windowMappings.showHelp
local trigger = windowMappings.trigger
local mappings = windowMappings.mappings
function getModifiersStr(modifiers)
local modMap = { shift = '', ctrl = '', alt = '', cmd = '' }
local retVal = ''
for i, v in ipairs(modifiers) do
retVal = retVal .. modMap[v]
end
return retVal
end
local msgStr = getModifiersStr(modifiers)
msgStr = 'Window Layout Mode (' .. msgStr .. (string.len(msgStr) > 0 and '+' or '') .. trigger .. ')'
for i, mapping in ipairs(mappings) do
local modifiers, trigger, winFunction = table.unpack(mapping)
local hotKeyStr = getModifiersStr(modifiers)
if showHelp == true then
if string.len(hotKeyStr) > 0 then
msgStr = msgStr .. (string.format('\n%10s+%s => %s', hotKeyStr, trigger, winFunction))
else
msgStr = msgStr .. (string.format('\n%11s => %s', trigger, winFunction))
end
end
windowLayoutMode:bindWithAutomaticExit(modifiers, trigger, function()
--example: hs.window.focusedWindow():upRight()
local fw = hs.window.focusedWindow()
fw[winFunction](fw)
end)
end
local message = require('keyboard.status-message')
windowLayoutMode.statusMessage = message.new(msgStr)
-- Use modifiers+trigger to toggle WindowLayout Mode
hs.hotkey.bind(modifiers, trigger, function()
windowLayoutMode:enter()
end)
windowLayoutMode:bind(modifiers, trigger, function()
windowLayoutMode:exit()
end)
-- https://github.com/dbalatero/VimMode.spoon/tree/21805205e39cc693dbf6ea671d47f2c5ba920262#manual-instructions
--------------------------------
-- TODO: check this out, seems cool
--------------------------------
--local VimMode = hs.loadSpoon("VimMode")
--local vim = VimMode:new()
---- Configure apps you do *not* want Vim mode enabled in
---- For example, you don't want this plugin overriding your control of Terminal
---- vim
--vim
-- :disableForApp('Code')
-- :disableForApp('zoom.us')
-- :disableForApp('iTerm')
-- :disableForApp('iTerm2')
-- :disableForApp('Terminal')
---- 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')
---- if you want to bind a single key to entering vim, remove the
---- :enterWithSequence('jk') line above and uncomment the bindHotKeys line
---- below:
----
---- To customize the hot key you want, see the mods and key parameters at:
---- https://www.hammerspoon.org/docs/hs.hotkey.html#bind
----
---- vim:bindHotKeys({ enter = { {'ctrl'}, ';' } })
----------------------------------
---- END VIM CONFIG
----------------------------------