Skip to content

Instantly share code, notes, and snippets.

@vishnu667
Created July 6, 2021 01:56
Show Gist options
  • Save vishnu667/5a6ad75ee325ce1e9e51e7e9218cb112 to your computer and use it in GitHub Desktop.
Save vishnu667/5a6ad75ee325ce1e9e51e7e9218cb112 to your computer and use it in GitHub Desktop.
DotFiles
-- vishnu667.com
local bind_key = {"cmd", "ctrl","alt"}
-- Move to left.
hs.hotkey.bind(bind_key, "left", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
local half = max.w / 2
local errm = max.w / 50
if math.floor(f.w)==math.floor(half) and math.floor(f.x)== math.floor(max.x) then
f.w = max.w / 4
else
if math.floor(f.w)==math.floor(max.w / 4) and math.floor(f.x)== math.floor(max.x) then
f.w = 3 * max.w / 4
else
f.w = half
end
end
f.x = max.x
f.y = max.y
f.h = max.h
win:setFrame(f)
end)
-- Move to right.
hs.hotkey.bind(bind_key, "right", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
local half = max.x + (max.w / 2)
if math.floor(f.w) == math.floor(max.w / 2) and math.floor(max.x + (max.w / 2))== math.floor(f.x) then
f.x = half + (max.w / 4)
f.w = max.w / 4
else
if math.floor(f.w) == math.floor(max.w / 4) and math.floor(half + (max.w / 4))== math.floor(f.x) then
f.x = half - (max.w / 4)
f.w = 3 * (max.w / 4)
else
f.x = max.x + (max.w / 2)
f.w = max.w / 2
end
end
f.y = max.y
f.h = max.h
win:setFrame(f)
end)
-- Move to top.
hs.hotkey.bind(bind_key, "up", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
local half = max.h / 2
local diff = math.abs(f.h - half)
local errm = max.h / 50
if math.floor(f.h)== math.floor(half) then
f.h = max.h / 4
else
if math.floor(f.h)==math.floor(max.h / 4) then
f.h = 3 * (max.h / 4)
else
f.h = half
end
end
f.y = max.y
win:setFrame(f)
end)
-- Move to bottom.
hs.hotkey.bind(bind_key, "down", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
local half = max.h / 2
local errm = max.h / 50
if math.floor(f.y)== math.floor(half) then
f.y = half + ( max.h / 4 )
f.h = max.h / 4
else
if math.floor(f.y)== math.floor(half + ( max.h / 4 )) and math.floor(f.h)==math.floor(max.h / 4) then
f.y = half - ( max.h / 4 )
f.h = 3 * (max.h / 4)
else
f.y = half
f.h = half
end
end
win:setFrame(f)
end)
hs.hotkey.bind(bind_key, "M", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end)
hs.fnutils.each({
{ key = "C", app = "Google Chrome" },
{ key = "S", app = "Mattermost" },
{ key = "T", app = "iTerm" }
}, function(object)
hs.hotkey.bind(bind_key, object.key, function() hs.application.launchOrFocus(object.app) end)
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "U", function()
hs.reload()
end)
hs.alert.show("Config loaded")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment