Skip to content

Instantly share code, notes, and snippets.

@jvandyke
Created November 12, 2015 15:09
Show Gist options
  • Save jvandyke/2a3ce9dd695173083c40 to your computer and use it in GitHub Desktop.
Save jvandyke/2a3ce9dd695173083c40 to your computer and use it in GitHub Desktop.
My Mjolnir configuration. https://github.com/sdegutis/mjolnir

All the following commands use hyper plus the key listed:

  • enter - Default layout (edit in init.lua)
  • up - Make current window fullscreen
  • down - Place current window in center of screen
  • right - place current window in right half
  • left - place current window in left half
  • a - Quick app switcher
  • j - Quick window switcher (focused app)
  • d - Move current window to other screen
-- Load Extensions
local application = require "mjolnir.application"
local window = require "mjolnir.window"
local hotkey = require "mjolnir.hotkey"
local keycodes = require "mjolnir.keycodes"
local fnutils = require "mjolnir.fnutils"
local notification = require("mjolnir._asm.ui.notification")
local screen = require "mjolnir.screen"
-- User packages
local grid = require "mjolnir.bg.grid"
local spotify = require "mjolnir.lb.spotify"
local hints = require "mjolnir.th.hints"
local appfinder = require "mjolnir.cmsj.appfinder"
local hotkeys = {}
local hyperDefinitions = nil
local modDefinitions = nil
local hyper = nil
local mod = nil
local modUp = nil
auxWin = nil
-- Functions =====================================
function notify(message)
n = notification.new({
title = message
})
n:send()
end
local gridset = function(frame)
return function()
local win = window.focusedwindow()
if win then
grid.set(win, frame, win:screen())
else
notify("No focused window.")
end
end
end
function saveFocus()
auxWin = window.focusedwindow()
notify("Window '" .. auxWin:title() .. "' saved.")
end
function focusSaved()
if auxWin then
auxWin:focus()
end
end
function createHotkeys()
for key, fun in pairs(hyperDefinitions) do
hotkey.bind(hyper, key, fun)
end
for key, fun in pairs(modDefinitions) do
hotkey.bind(mod, key, fun)
end
for key, fun in pairs(modUpDefinitions) do
hotkey.bind(mod, key, fun)
end
end
function rebindHotkeys()
for i, hk in ipairs(hotkeys) do
hk:disable()
end
hotkeys = {}
createHotkeys()
notify("Rebound Hotkeys")
end
function applyPlace(win, place)
local scrs = screen:allscreens()
local scr = scrs[place[1]]
grid.set(win, place[2], scr)
end
function applyLayout(layout)
return function()
for appName, place in pairs(layout) do
local app = appfinder.app_from_name(appName)
if app then
for i, win in ipairs(app:allwindows()) do
applyPlace(win, place)
end
end
end
end
end
function show()
-- body
end
function init()
createHotkeys()
keycodes.inputsourcechanged(rebindHotkeys)
notify("Mjolnir, at your service.")
end
-- Actual config =================================
hyper = {"cmd", "alt", "ctrl", "shift"}
-- hyper = {"f19"}
mod = {"cmd", "ctrl"}
modUp = {"cmd", "ctrl", "shift"}
-- Set grid size.
grid.GRIDWIDTH = 6
grid.GRIDHEIGHT = 8
grid.MARGINX = 0
grid.MARGINY = 0
local gw = grid.GRIDWIDTH
local gh = grid.GRIDHEIGHT
local gomiddle = {x = 1, y = 1, w = 4, h = 6}
local goleft = {x = 0, y = 0, w = gw/2, h = gh}
local goright = {x = gw/2, y = 0, w = gw/2, h = gh}
local gobig = {x = 0, y = 0, w = gw, h = gh}
local gobigleft = {x = 0, y = 0, w = gw/3*2, h = gh}
local gobigright = {x = gw/3, y = 0, w = gw/3*2, h = gh}
-- Main layout. Where known apps should be placed.
local layout = {
-- Primary screen apps
["Sublime Text"] = {1, goleft},
["Atom"] = {1, goleft},
["Google Chrome"] = {1, goright},
["FirefoxDeveloperEdition"] = {1, goright},
["Firefox"] = {1, goright},
-- Secondary screen apps
Spotify = {1, gomiddle},
iTerm = {2, gobig},
["Slack"] = {2, gobig},
["HipChat"] = {2, gobig},
["Nylas N1"] = {2, gobig},
}
-- Key bindings go here
-- To have multiple keys perform the same action, bind
-- the keys separately.
hyperDefinitions = {
[";"] = saveFocus,
["'"] = focusSaved,
down = gridset(gomiddle),
left = gridset(goleft),
up = grid.maximize_window,
right = gridset(goright),
-- number pad bindings
pad4 = gridset(goleft),
pad6 = gridset(goright),
pad5 = gridset(gomiddle),
pad8 = gridset(gobig),
["pad+"] = grid.pushwindow_nextscreen,
["return"] = applyLayout(layout),
d = grid.pushwindow_nextscreen,
r = mjolnir.reload,
-- q = function() appfinder.app_from_name("Mjolnir"):kill() end,
s = function() hints.appHints(appfinder.app_from_name("Sublime Text")) end,
j = function() hints.appHints(window.focusedwindow():application()) end,
a = hints.windowHints,
t = function() notify(window.focusedwindow():application():title()) end
}
modDefinitions = {
left = gridset(gobigleft),
right = gridset(gobigright),
}
modUpDefinitions = {
["?"] = showHelp
}
init()
  1. Download Mjolnir and install Mjolnir.app from https://github.com/sdegutis/mjolnir/releases/latest
  2. Run the following commands
brew update
brew install lua
echo 'rocks_servers = { "http://rocks.moonscript.org" }' >> /usr/local/etc/luarocks52/config-5.2.lua

luarocks install mjolnir.hotkey
luarocks install mjolnir.application
luarocks install mjolnir.keycodes
luarocks install mjolnir.fnutils
luarocks install mjolnir._asm.ui.notification
luarocks install mjolnir.screen
luarocks install mjolnir.bg.grid
luarocks install mjolnir.lb.spotify
luarocks install mjolnir.th.hints
luarocks install mjolnir.cmsj.appfinder

mkdir ~/.mjolnir
edit  ~/.mjolnir/init.lua
  1. Get a hyper key http://www.tenshu.net/p/fake-hyper-key-for-osx.html
  2. Run Mjolnir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment