dotfiles

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

init.lua (2724B)


      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 -- Copy current mouse position
     44 bindkey(hyper, "m", function()
     45   local pos = mouse.pos()
     46   hs.pasteboard.setContents(string.format("{x = %f, y = %f}", pos.x, pos.y))
     47 end)
     48 
     49 -- "fn" is actually needed for this to work for some reason
     50 -- https://github.com/Hammerspoon/hammerspoon/issues/1946#issuecomment-449604954
     51 bindkey({}, "f6", function()
     52   key({ "fn", "ctrl" }, "right")
     53 end)
     54 bindkey({}, "f5", function()
     55   key({ "fn", "ctrl" }, "left")
     56 end)
     57 
     58 -- Toggle terminal
     59 bindkey({ "alt" }, "space", function()
     60   local appName = "Alacritty"
     61   local runningApp = hs.application.get(appName)
     62   if runningApp ~= nil and runningApp:isFrontmost() then
     63     runningApp:hide()
     64   else
     65     hs.application.open(appName)
     66   end
     67 end)
     68 
     69 -- Emacs
     70 bindkey(hyper, "e", function()
     71   hs.application.open("Emacs")
     72 end)
     73 
     74 -- Play/pause mpd
     75 bindkey({}, 100, function()
     76   hs.execute("/usr/local/bin/mpc toggle")
     77 end)
     78 
     79 -- bind other keyboard keys
     80 Kbd_tap = eventtap.new({ hs.eventtap.event.types.systemDefined }, function(ev)
     81   -- http://www.hammerspoon.org/docs/hs.eventtap.event.html#systemKey
     82   ev = ev:systemKey()
     83   -- http://stackoverflow.com/a/1252776/1521064
     84   local next = next
     85   -- Check empty table
     86   if next(ev) then
     87     if ev.key == "EJECT" and ev.down then
     88       hs.execute("/run/current-system/sw/bin/alacritty -e /usr/local/bin/ncmpcpp")
     89     end
     90   end
     91 end)
     92 Kbd_tap:start()
     93 
     94 -- bind mouse keys
     95 Mousebtn_tap = eventtap.new({ events.otherMouseDown }, function(ev)
     96   local mouseBtn = ev:getProperty(eventProps.mouseEventButtonNumber)
     97   if mouseBtn == 3 then
     98     spaces.toggleLaunchPad()
     99     return true
    100   elseif mouseBtn == 4 then
    101     spaces.toggleMissionControl()
    102     return true
    103   end
    104   return false
    105 end)
    106 Mousebtn_tap:start()
    107 
    108 -- require("mydebug"):monitorKeys()