Extract host specific hammerspoon config to separate files

This commit is contained in:
2018-04-29 16:27:55 +01:00
parent 556960a588
commit 4eddfdf6ac
5 changed files with 65 additions and 41 deletions

View File

@@ -2,16 +2,13 @@ local obj = {
hostname = nil
}
function obj:init()
self.hostname = self.getHostname()
end
function obj:getHostname()
local f = io.popen ("hostname")
function obj.getHostname()
local f = io.popen ("hostname -s")
local hostname = f:read("*a") or ""
f:close()
hostname = string.gsub(hostname, "\n$", "")
return hostname
end
obj.hostname = obj.getHostname()
return obj

View File

@@ -0,0 +1,20 @@
local obj = {}
function obj:init()
local env = require('env')
local conf_file = "hosts/" .. env.hostname .. ".lua"
local conf_req = "hosts." .. env.hostname
if self.file_exists(conf_file) then
print("loading host config: " .. conf_file)
local conf_module = require(conf_req)
conf_module:init()
end
end
function obj.file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
return obj

View File

@@ -0,0 +1,17 @@
local obj = {}
function obj.init()
local apptoggle = require('app_toggle')
apptoggle:bind({'alt', 'ctrl'}, 'A', 'Activity Monitor')
apptoggle:bind({'cmd', 'ctrl'}, 'B', 'Sequel Pro')
apptoggle:bind({'cmd', 'ctrl'}, 'C', 'Paw')
apptoggle:bind({'cmd', 'ctrl'}, 'D', 'Mail')
apptoggle:bind({'cmd', 'ctrl'}, 'E', 'Emacs', '/Applications/Emacs.app')
apptoggle:bind({'cmd', 'ctrl'}, 'G', 'Slack')
apptoggle:bind({'cmd', 'ctrl'}, 'S', 'Skype for Business')
apptoggle:bind({'cmd', 'ctrl'}, 'X', 'Calendar')
apptoggle:bind({'cmd', 'ctrl'}, 'Z', 'Stride')
end
return obj

View File

@@ -0,0 +1,22 @@
local obj = {}
function obj.init()
local apptoggle = require('app_toggle')
apptoggle:bind({'cmd', 'alt', 'ctrl'}, 'A', 'Activity Monitor')
apptoggle:bind({'cmd', 'ctrl'}, '4', 'Skitch')
apptoggle:bind({'cmd', 'ctrl'}, 'A', 'YakYak')
apptoggle:bind({'cmd', 'ctrl'}, 'B', 'Portico')
apptoggle:bind({'cmd', 'ctrl'}, 'C', 'Medis')
apptoggle:bind({'cmd', 'ctrl'}, 'D', 'Wavebox')
apptoggle:bind({'cmd', 'ctrl'}, 'E', 'Emacs', '/Applications/Emacs.app')
apptoggle:bind({'cmd', 'ctrl'}, 'F', 'Messenger')
apptoggle:bind({'cmd', 'ctrl'}, 'G', 'Stride')
apptoggle:bind({'cmd', 'ctrl'}, 'S', 'Skype')
apptoggle:bind({'cmd', 'ctrl'}, 'T', 'IRCCloud')
apptoggle:bind({'cmd', 'ctrl'}, 'W', 'WhatsApp')
apptoggle:bind({'cmd', 'ctrl'}, 'X', 'Calendar')
apptoggle:bind({'cmd', 'ctrl'}, 'Z', 'Slack')
end
return obj

View File

@@ -4,13 +4,6 @@
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'R', hs.reload)
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'C', hs.toggleConsole)
--------------------------------------------------------------------------------
-- Environment
--------------------------------------------------------------------------------
local env = require('env')
env:init()
--------------------------------------------------------------------------------
-- Set Hammerspoon options
--------------------------------------------------------------------------------
@@ -36,36 +29,11 @@ spoon.HeadphoneAutoPause.autoResume = false
spoon.HeadphoneAutoPause:start()
--------------------------------------------------------------------------------
-- Application toggles
-- Host specific configuration
--------------------------------------------------------------------------------
local apptoggle = require('app_toggle')
apptoggle:bind({'cmd', 'ctrl'}, 'E', 'Emacs', '/Applications/Emacs.app')
apptoggle:bind({'cmd', 'ctrl'}, 'X', 'Calendar')
if env.hostname == "UAC00024" then
apptoggle:bind({'alt', 'ctrl'}, 'A', 'Activity Monitor')
apptoggle:bind({'cmd', 'ctrl'}, 'B', 'Sequel Pro')
apptoggle:bind({'cmd', 'ctrl'}, 'C', 'Paw')
apptoggle:bind({'cmd', 'ctrl'}, 'D', 'Mail')
apptoggle:bind({'cmd', 'ctrl'}, 'G', 'Slack')
apptoggle:bind({'cmd', 'ctrl'}, 'S', 'Skype for Business')
apptoggle:bind({'cmd', 'ctrl'}, 'Z', 'Stride')
else
apptoggle:bind({'cmd', 'alt', 'ctrl'}, 'A', 'Activity Monitor')
apptoggle:bind({'cmd', 'ctrl'}, '4', 'Skitch')
apptoggle:bind({'cmd', 'ctrl'}, 'A', 'YakYak')
apptoggle:bind({'cmd', 'ctrl'}, 'B', 'Portico')
apptoggle:bind({'cmd', 'ctrl'}, 'C', 'Medis')
apptoggle:bind({'cmd', 'ctrl'}, 'D', 'Wavebox')
apptoggle:bind({'cmd', 'ctrl'}, 'F', 'Messenger')
apptoggle:bind({'cmd', 'ctrl'}, 'G', 'Stride')
apptoggle:bind({'cmd', 'ctrl'}, 'S', 'Skype')
apptoggle:bind({'cmd', 'ctrl'}, 'T', 'IRCCloud')
apptoggle:bind({'cmd', 'ctrl'}, 'W', 'WhatsApp')
apptoggle:bind({'cmd', 'ctrl'}, 'Z', 'Slack')
end
local hostconfig = require('host_config')
hostconfig:init()
--------------------------------------------------------------------------------
-- Window management