Files
dotfiles/hammerspoon/.hammerspoon/init.lua
Konstantin Bukley 126445d2bd bash: cleanup
2022-04-19 14:42:00 +03:00

301 lines
6.8 KiB
Lua

--------------------------------------------------------------------------
hyperModeAppMappings = {
{ 'a', 'Alacritty' }, -- "A" for "Alacritty"
{ 's', 'Slack' }, -- "S" for "Slack"
{ 't', 'Telegram' }, -- "T" for "Telegram"
{ 'd', 'Discord' }, -- "D" for "Discord"
{ 'f', 'Finder' }, -- "F" for "Finder"
{ 'm', 'Spark' }, -- "M" for "Mail"
{ 'y', 'Spotify' }, -- "Y" for "SpotifY"
{ 'b', 'Brave Browser' }, -- "B" for "Brave" or "Browser"
{ 'o', 'Obsidian' } -- "O" for "Obsidian"
}
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.launchOrFocus(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")
window.animationDuration = 0
-- +-----------------+
-- | | |
-- | 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
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()
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)