Commit for new branch
[dotfiles.git] / hammerspoon / init.lua
index f30a5b6..0d0eb83 100644 (file)
@@ -191,3 +191,26 @@ INSTALL:andUse("Seal",
                   start = true,
                }
 )
+--------------------------------------------------------------------------------
+-- Focus the last used window.
+local function focusLastFocused()
+    local wf = hs.window.filter
+    local lastFocused = wf.defaultCurrentSpace:getWindows(wf.sortByFocusedLast)
+    if #lastFocused > 0 then lastFocused[1]:focus() end
+end
+
+-- Create the chooser.
+-- On selection, copy the emoji and type it into the focused application.
+local chooser = hs.chooser.new(function(choice)
+    if not choice then focusLastFocused(); return end
+    hs.pasteboard.setContents(choice["chars"])
+    focusLastFocused()
+    hs.eventtap.keyStrokes(hs.pasteboard.getContents())
+end)
+
+chooser:searchSubText(true)
+chooser:choices(choices)
+
+chooser:rows(5)
+chooser:bgDark(true)
+hs.hotkey.bind({"cmd", "alt"}, "E", function() chooser:show() end)