dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

init.lua (2820B)


      1 local hyper = { "alt", "cmd", "shift", "ctrl" }
      2 local eventtap = hs.eventtap
      3 local events = hs.eventtap.event.types
      4 local eventProps = hs.eventtap.event.properties
      5 local spaces = hs.spaces
      6 local bindkey = hs.hotkey.bind
      7 
      8 -- Mouse events
      9 local mouse = {
     10   l = eventtap.leftClick,
     11   r = eventtap.rightClick,
     12   pos = hs.mouse.absolutePosition,
     13 }
     14 
     15 -- Press a key
     16 local key = eventtap.keyStroke
     17 
     18 -- Set up WM
     19 require("spoonconfig.paperwm").setup({
     20   paperWmMod = { "alt", "shift" },
     21   paperWmMoveMod = { "alt", "ctrl", "shift" },
     22 })
     23 
     24 hs.loadSpoon("ClipboardTool")
     25 spoon.ClipboardTool:bindHotkeys({
     26   show_clipboard = { hyper, "c" },
     27 })
     28 spoon.ClipboardTool.show_copied_alert = false
     29 spoon.ClipboardTool:start()
     30 
     31 require("spoonconfig.swipe")
     32 
     33 require("numpad-cursor")
     34 
     35 -- Automatically switch vertical/horizontal tabs in Brave
     36 require("auto-toggle-vertical-horizontal-tabs")
     37 
     38 bindkey(hyper, "r", function()
     39   hs.reload()
     40   hs.notify.show("Config reloaded", "New config applied", "")
     41 end)
     42 
     43 bindkey({}, "f3", hs.spaces.toggleMissionControl)
     44 bindkey({}, "f4", hs.spaces.toggleLaunchPad)
     45 
     46 -- Copy current mouse position
     47 bindkey(hyper, "m", function()
     48   local pos = mouse.pos()
     49   hs.pasteboard.setContents(string.format("{x = %f, y = %f}", pos.x, pos.y))
     50 end)
     51 
     52 -- "fn" is actually needed for this to work for some reason
     53 -- https://github.com/Hammerspoon/hammerspoon/issues/1946#issuecomment-449604954
     54 bindkey({}, "f6", function()
     55   key({ "fn", "ctrl" }, "right")
     56 end)
     57 bindkey({}, "f5", function()
     58   key({ "fn", "ctrl" }, "left")
     59 end)
     60 
     61 -- Toggle terminal
     62 bindkey({ "alt" }, "space", function()
     63   local appName = "Alacritty"
     64   local runningApp = hs.application.get(appName)
     65   if runningApp ~= nil and runningApp:isFrontmost() then
     66     runningApp:hide()
     67   else
     68     hs.application.open(appName)
     69   end
     70 end)
     71 
     72 -- Emacs
     73 bindkey(hyper, "e", function()
     74   hs.application.open("Emacs")
     75 end)
     76 
     77 -- Play/pause mpd
     78 bindkey({}, 100, function()
     79   hs.execute("/usr/local/bin/mpc toggle")
     80 end)
     81 
     82 -- bind other keyboard keys
     83 Kbd_tap = eventtap.new({ hs.eventtap.event.types.systemDefined }, function(ev)
     84   -- http://www.hammerspoon.org/docs/hs.eventtap.event.html#systemKey
     85   ev = ev:systemKey()
     86   -- http://stackoverflow.com/a/1252776/1521064
     87   local next = next
     88   -- Check empty table
     89   if next(ev) then
     90     if ev.key == "EJECT" and ev.down then
     91       hs.execute("/run/current-system/sw/bin/alacritty -e /usr/local/bin/ncmpcpp")
     92     end
     93   end
     94 end)
     95 Kbd_tap:start()
     96 
     97 -- bind mouse keys
     98 Mousebtn_tap = eventtap.new({ events.otherMouseDown }, function(ev)
     99   local mouseBtn = ev:getProperty(eventProps.mouseEventButtonNumber)
    100   if mouseBtn == 3 then
    101     spaces.toggleLaunchPad()
    102     return true
    103   elseif mouseBtn == 4 then
    104     spaces.toggleMissionControl()
    105     return true
    106   end
    107   return false
    108 end)
    109 Mousebtn_tap:start()
    110 
    111 -- require("mydebug"):monitorKeys()