Emacs - change irony to ycmd
[dotfiles.git] / hammerspoon / init.lua
1 -- Sample Hello World 
2 hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
3   hs.notify.new({title="Hammerspoon", informativeText="Hello World"}):send()
4 --  hs.alert.show("Hello World!")
5 end)
6
7 -- Reload configuration
8 hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
9   hs.reload()
10 end)
11 hs.alert.show("Config loaded")
12
13 -- Reacting to application events
14 -- Move all Finder in front
15 function applicationWatcher(appName, eventType, appObject)
16     if (eventType == hs.application.watcher.activated) then
17         if (appName == "Finder") then
18             -- Bring all Finder windows forward when one gets activated
19             appObject:selectMenuItem({"Window", "Bring All to Front"})
20         end
21     end
22 end
23 appWatcher = hs.application.watcher.new(applicationWatcher)
24 appWatcher:start()
25
26
27 -- Window Movement
28 -- https://andrich.blog/2016/11/20/hammerspoon-an-awesome-tool-to-automate-your-mac/
29 -- CTRL + ALT + Left - Move current window to the left half of the screen.
30 -- CTRL + ALT + Right - Move current window to the right half of the screen.
31 -- CTRL + ALT + Up - Go "fullscreen".
32 -- CTRL + ALT + Down - Center window, covering 2/3 of screen size.
33 --
34  
35 function move_window(direction)
36     return function()
37         local win      = hs.window.focusedWindow()
38         local app      = win:application()
39         local app_name = app:name()
40         local f        = win:frame()
41         local screen   = win:screen()
42         local max      = screen:frame()
43  
44         if direction == "left" then
45             f.x = max.x
46             f.y = max.y
47             f.w = max.w / 2
48             f.h = max.h
49         elseif direction == "right" then
50             f.x = max.x + (max.w / 2)
51             f.y = max.y
52             f.w = max.w / 2
53             f.h = max.h
54         elseif direction == "up" then
55             f.x = max.x
56             f.y = max.y 
57             f.w = max.w
58             f.h = max.h / 2
59         elseif direction == "down" then
60             f.x = max.x 
61             f.y = max.y + (max.h / 2)
62             f.w = max.w 
63             f.h = max.h / 2
64         elseif direction == "max" then
65            if f.w > (max.w * 3/4) and f.h > (max.h * 3/4) then
66                 f.x = max.x + (max.w / 6)
67                 f.y = max.y + (max.h / 6)
68                 f.w = max.w * 2 / 3
69                 f.h = max.h * 2 / 3
70            else
71                 f.x = max.x 
72                 f.y = max.y
73                 f.w = max.w 
74                 f.h = max.h
75            end
76         else
77             hs.alert.show("move_window(): Freaky parameter received " .. direction)
78         end
79  
80         win:setFrame(f, 0)
81     end
82 end
83  
84 local hyper = {"ctrl", "cmd"}
85 hs.hotkey.bind(hyper, "h", move_window("left"))
86 hs.hotkey.bind(hyper, "l", move_window("right"))
87 hs.hotkey.bind(hyper, "k", move_window("up"))
88 hs.hotkey.bind(hyper, "j", move_window("down"))
89 hs.hotkey.bind(hyper, "m", move_window("max"))
90
91 -- Search and dictionary
92 -- Past and copy
93 -- App quick startup
94
95 -- Use SpoonInstall,
96 -- http://zzamboni.org/post/using-spoons-in-hammerspoon/
97 -- https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip
98 if hs.spoons == nil then
99    hs.spoons=require('hs.spoons')
100 end
101
102
103 hs.loadSpoon ("SpoonInstall")
104 spoon.SpoonInstall.use_syncinstall = true
105 INSTALL = spoon.SpoonInstall
106
107 --------------------------------------------------------------------------------
108 -- MouseCircle  http://www.hammerspoon.org/Spoons/MouseCircle.html
109 INSTALL:andUse("MouseCircle",
110                 {
111                    disable = false,
112                    config = {
113                       color = hs.drawing.color.x11.rebeccapurple
114                    },
115                    hotkeys = {
116                       show = { {"cmd", "alt", "ctrl"}, "m"}
117                    }
118                 }
119 )
120
121 --------------------------------------------------------------------------------
122 -- TextClipboardHistory
123 INSTALL:andUse("TextClipboardHistory",
124                {
125                   config = {
126                      show_in_menubar = false,
127                      hist_size = 500,
128                   },
129                   hotkeys = {
130                      toggle_clipboard = { { "cmd", "shift" }, "v"}
131                   },
132                   start = true;
133                }
134 )
135
136
137 --------------------------------------------------------------------------------
138 -- Seal -- http://www.hammerspoon.org/Spoons/Seal.html
139 INSTALL:andUse("Seal",
140                {
141                   hotkeys = { show = { {"cmd", "ctrl", "alt"}, "space" } },
142                   fn = function(s)
143                      s:loadPlugins({"apps", "calc", "safari_bookmarks", "screencapture", "useractions"})
144                      s.plugins.safari_bookmarks.always_open_with_safari = false
145                      s.plugins.useractions.actions =
146                         {
147                            ["Hammerspoon docs webpage"] = {
148                               url = "http://hammerspoon.org/docs/",
149                               icon = hs.image.imageFromName(hs.image.systemImageNames.ApplicationIcon),
150                               -- hotkey = { hyper, "h" }
151                            },
152                            ["Leave corpnet"] = {
153                               fn = function()
154                                  spoon.WiFiTransitions:processTransition('foo', 'corpnet01')
155                               end,
156                               icon = swisscom_logo,
157                            },
158                            ["Arrive in corpnet"] = {
159                               fn = function()
160                                  spoon.WiFiTransitions:processTransition('corpnet01', 'foo')
161                               end,
162                               icon = swisscom_logo,
163                            },
164                            ["Translate using Leo"] = {
165                               url = "http://dict.leo.org/ende/index_de.html#/search=${query}",
166                               icon = 'favicon',
167                               keyword = "leo",
168                            },
169                            ["Tell me something"] = {
170                               keyword = "tellme",
171                               fn = function(str) hs.alert.show(str) end,
172                            }
173                         }
174                      s:refreshAllCommands()
175                   end,
176                   start = true,
177                }
178 )