Skip to content

Instantly share code, notes, and snippets.

@AndreFCruz
Last active March 28, 2021 09:01
Show Gist options
  • Select an option

  • Save AndreFCruz/5daaa0075bcebfaa8a751c490473c87d to your computer and use it in GitHub Desktop.

Select an option

Save AndreFCruz/5daaa0075bcebfaa8a751c490473c87d to your computer and use it in GitHub Desktop.
My Hammerspoon configuration.
local obj = {}
obj.__index = obj
obj.menuBarItem = nil
function obj:start()
self.menuBarItem = hs.menubar.new()
self.menuBarItem:setClickCallback(self.clicked)
self.setDisplay(hs.caffeinate.get("displayIdle"))
return self
end
function obj.setDisplay(state)
if state then
obj.menuBarItem:setTitle("AWAKE")
-- result = obj.menuBarItem:setIcon("caffeine-on.pdf")
else
obj.menuBarItem:setTitle("SLEEPY")
-- result = obj.menuBarItem:setIcon("caffeine-off.pdf")
end
end
function obj.clicked()
obj.setDisplay(hs.caffeinate.toggle("displayIdle"))
end
return obj
-- - Dual Monitor Hotkeys - --
-- Hotkey Definition - CAPS is mapped to CTRL using karabiner --
hyper = {"ctrl"}
hyper_cmd = {"ctrl", "cmd"}
hyper_shft = {"ctrl", "shift"}
-- - Dual Monitor Functions - --
function toEastMonitor()
w = hs.window.frontmostWindow()
w:moveOneScreenEast()
end
function toWestMonitor()
w = hs.window.frontmostWindow()
w:moveOneScreenWest()
end
function toNorthMonitor()
w = hs.window.frontmostWindow()
w:moveOneScreenNorth()
end
function toSouthMonitor()
w = hs.window.frontmostWindow()
w:moveOneScreenSouth()
end
dell_screen = hs.screen.find('DELL P2418D')
if dell_screen then
x, y = dell_screen:position()
if x == 0 then
hs.hotkey.bind(hyper, 'O', toNorthMonitor)
hs.hotkey.bind(hyper, 'L', toSouthMonitor)
else
hs.hotkey.bind(hyper, 'L', toEastMonitor)
hs.hotkey.bind(hyper, 'K', toWestMonitor)
end
end
-- Hotkey Definition - CAPS is mapped to CTRL using karabiner --
hyper = {"ctrl"}
hyper_cmd = {"ctrl", "cmd"}
hyper_shft = {"ctrl", "shift"}
-- Launch Applications --
hs.hotkey.bind(hyper, 'T', "Terminal", function () hs.application.launchOrFocus("Terminal") end)
hs.hotkey.bind(hyper, 'R', "Sublime Text", function () hs.application.launchOrFocus("Sublime Text") end)
hs.hotkey.bind(hyper, 'S', "Safari", function () hs.application.launchOrFocus("Safari") end)
hs.hotkey.bind(hyper_cmd, 'S', "Spotify", function () hs.application.launchOrFocus("Spotify") end)
hs.hotkey.bind(hyper, 'F', "Finder", function () hs.application.launchOrFocus("Finder") end)
hs.hotkey.bind(hyper_cmd, 'C', "Google Chrome", function () hs.application.launchOrFocus("Google Chrome") end)
hs.hotkey.bind(hyper_cmd, 'V', "Visual Studio Code", function () hs.application.launchOrFocus("Visual Studio Code") end)
hs.hotkey.bind(hyper_cmd, 'M', "Caprine", function () hs.application.launchOrFocus("Caprine") end)
hs.hotkey.bind(hyper_cmd, 'D', "Dash", function () hs.application.launchOrFocus("Dash") end)
-- Window Hints --
hs.hotkey.bind(hyper, '.', hs.hints.windowHints)
-- Reload Hammerspoon Config --
hs.hotkey.bind(hyper_cmd, 'R', hs.reload)
-- Spotify --
-- Notification For Current Song --
function displayCurrentSpotifySong()
hs.notify.new(nil, {
alwaysPresent = true,
autoWithdraw = true,
title = hs.spotify.getCurrentArtist(),
informativeText = hs.spotify.getCurrentTrack() .. ' - ' .. hs.spotify.getCurrentAlbum(),
subtitle = "Spotify"
})
:setIdImage('/Applications/Spotify.app/Contents/Resources/Icon.icns')
:send()
end
hs.hotkey.bind(hyper_cmd, 'P', displayCurrentSpotifySong)
-- Hotkey Definition - CAPS is mapped to CTRL using karabiner --
hyper = {"ctrl"}
hyper_cmd = {"ctrl", "cmd"}
hyper_shft = {"ctrl", "shift"}
-- Disable Animations
hs.window.animationDuration = 0
-- Hotkeys --
require('hotkeys')
-- Grid Layout --
require('layout')
-- Dual Monitor Setup --
require('dual_monitor')
-- Caffeine --
caffeine = require("caffeine"):start()
-- - Grid Layout - --
-- Hotkey Definition - CAPS is mapped to CTRL using karabiner --
hyper = {"ctrl"}
hyper_cmd = {"ctrl", "cmd"}
hyper_shft = {"ctrl", "shift"}
-- init grid --
hs.grid.MARGINX = 0
hs.grid.MARGINY = 0
hs.grid.setGrid('2x2')
-- Organize Windows --
hs.hotkey.bind(hyper, 'W', hs.grid.maximizeWindow)
function toUpper ()
function fn (cell)
cell.y = 0
cell.x = 0
cell.w = 2
cell.h = 1
return hs.grid
end
hs.grid.adjustWindow(fn)
end
hs.hotkey.bind(hyper_shft, 'W', toUpper)
function toLower ()
function fn (cell)
cell.y = 1
cell.x = 0
cell.w = 2
cell.h = 1
return hs.grid
end
hs.grid.adjustWindow(fn)
end
hs.hotkey.bind(hyper_shft, 'S', toLower)
function toUpperLeft ()
function fn (cell)
cell.y = 0
cell.x = 0
cell.w = 1
return hs.grid
end
hs.grid.adjustWindow(fn)
end
hs.hotkey.bind(hyper, 'Q', toUpperLeft)
function toUpperRight ()
function fn (cell)
cell.y = 0
cell.x = 1
cell.w = 1
return hs.grid
end
hs.grid.adjustWindow(fn)
end
hs.hotkey.bind(hyper, 'E', toUpperRight)
function toLowerRight ()
function fn (cell)
cell.h = 1
cell.w = 1
cell.y = 1
cell.x = 1
end
hs.grid.adjustWindow(fn)
end
hs.hotkey.bind(hyper, 'D', toLowerRight)
function toLowerLeft ()
function fn (cell)
cell.h = 1
cell.w = 1
cell.y = 1
cell.x = 0
end
hs.grid.adjustWindow(fn)
end
hs.hotkey.bind(hyper, 'A', toLowerLeft)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment