half-baked re-implementation of the major parts of sdorfehs in Hammerspoon
at main 80 lines 1.8 kB view raw
1table.copy = function(tab) 2 local ret = {} 3 for k, v in pairs(tab) do 4 ret[k] = v 5 end 6 return ret 7end 8 9-- come on, lua 10table.count = function(tab) 11 local c = 0 12 for i, j in pairs(tab) do 13 c = c + 1 14 end 15 return c 16end 17 18table.keys = function(tab) 19 local ret = {} 20 for k, _ in pairs(tab) do 21 ret[#ret + 1] = k 22 end 23 return ret 24end 25 26spoonfish.dir_from_string = function(str) 27 lstr = str:lower() 28 29 if lstr == "left" then 30 return spoonfish.direction.LEFT 31 elseif lstr == "right" then 32 return spoonfish.direction.RIGHT 33 elseif lstr == "up" then 34 return spoonfish.direction.UP 35 elseif lstr == "down" then 36 return spoonfish.direction.DOWN 37 else 38 error("dir_from_string: invalid direction") 39 return nil 40 end 41end 42 43spoonfish.last_alert = nil 44spoonfish.alert = function(str) 45 if spoonfish.last_alert then 46 hs.alert.closeSpecific(spoonfish.last_alert, 0) 47 end 48 49 local style = hs.alert.defaultStyle 50 style["atScreenEdge"] = 2 51 spoonfish.last_alert = hs.alert(str, style) 52end 53 54spoonfish.inset = function(rect, ins) 55 return hs.geometry.rect(rect.x + ins, rect.y + ins, rect.w - (ins * 2), 56 rect.h - (ins * 2)) 57end 58 59spoonfish.dump_wins = function(wins) 60 for i, w in pairs(wins) do 61 print("win[" .. i .. "] space[" .. w["space"] .. "] frame[" .. 62 w["frame"] .. "] title:" .. w["win"]:title()) 63 end 64end 65 66spoonfish.dump_frames = function(space_id) 67 for i, f in pairs(spoonfish.spaces[space_id].frames) do 68 print("frame[" .. f["id"] .. "]") 69 end 70end 71 72spoonfish.escape_pattern = function(str) 73 local quotepattern = '(['..("%^$().[]*+-?"):gsub("(.)", "%%%1")..'])' 74 return str:gsub(quotepattern, "%%%1") 75end 76 77spoonfish.rect_s = function(rect) 78 return "{x:" .. rect.x .. " y:" .. rect.y .. " w:" .. rect.w .. " h:" .. 79 rect.h .. "}" 80end