use SpoonInstall

main
Alpha Chen 2 years ago
parent a287e38df9
commit 6ebfe69371
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -1,242 +0,0 @@
[
{
"Constant" : [
],
"submodules" : [
],
"Function" : [
],
"Variable" : [
{
"doc" : "The sizes that the window can have. \nThe sizes are expressed as dividend of the entire screen's size.\nFor example `{2, 3, 3\/2}` means that it can be 1\/2, 1\/3 and 2\/3 of the total screen's size",
"name" : "sizes",
"stripped_doc" : [
"The sizes that the window can have. ",
"The sizes are expressed as dividend of the entire screen's size.",
"For example `{2, 3, 3\/2}` means that it can be 1\/2, 1\/3 and 2\/3 of the total screen's size"
],
"parameters" : [
],
"notes" : [
],
"signature" : "MiroWindowsManager.sizes",
"type" : "Variable",
"returns" : [
],
"def" : "MiroWindowsManager.sizes",
"desc" : "The sizes that the window can have."
},
{
"doc" : "The sizes that the window can have in full-screen. \nThe sizes are expressed as dividend of the entire screen's size.\nFor example `{1, 4\/3, 2}` means that it can be 1\/1 (hence full screen), 3\/4 and 1\/2 of the total screen's size",
"name" : "fullScreenSizes",
"stripped_doc" : [
"The sizes that the window can have in full-screen. ",
"The sizes are expressed as dividend of the entire screen's size.",
"For example `{1, 4\/3, 2}` means that it can be 1\/1 (hence full screen), 3\/4 and 1\/2 of the total screen's size"
],
"parameters" : [
],
"notes" : [
],
"signature" : "MiroWindowsManager.fullScreenSizes",
"type" : "Variable",
"returns" : [
],
"def" : "MiroWindowsManager.fullScreenSizes",
"desc" : "The sizes that the window can have in full-screen."
},
{
"doc" : "The screen's size using `hs.grid.setGrid()`\nThis parameter is used at the spoon's `:init()`",
"name" : "GRID",
"stripped_doc" : [
"The screen's size using `hs.grid.setGrid()`",
"This parameter is used at the spoon's `:init()`"
],
"parameters" : [
],
"notes" : [
],
"signature" : "MiroWindowsManager.GRID",
"type" : "Variable",
"returns" : [
],
"def" : "MiroWindowsManager.GRID",
"desc" : "The screen's size using `hs.grid.setGrid()`"
}
],
"stripped_doc" : [
],
"desc" : "With this script you will be able to move the window in halves and in corners using your keyboard and mainly using arrows. You would also be able to resize them by thirds, quarters, or halves.",
"type" : "Module",
"Deprecated" : [
],
"Constructor" : [
],
"doc" : "With this script you will be able to move the window in halves and in corners using your keyboard and mainly using arrows. You would also be able to resize them by thirds, quarters, or halves.\n\nOfficial homepage for more info and documentation: [https:\/\/github.com\/miromannino\/miro-windows-manager](https:\/\/github.com\/miromannino\/miro-windows-manager)\n\nDownload: [https:\/\/github.com\/miromannino\/miro-windows-manager\/raw\/master\/MiroWindowsManager.spoon.zip](https:\/\/github.com\/miromannino\/miro-windows-manager\/raw\/master\/MiroWindowsManager.spoon.zip)",
"Method" : [
{
"doc" : "Binds hotkeys for Miro's Windows Manager\nParameters:\n * mapping - A table containing hotkey details for the following items:\n * up: for the up action (usually {hyper, \"up\"})\n * right: for the right action (usually {hyper, \"right\"})\n * down: for the down action (usually {hyper, \"down\"})\n * left: for the left action (usually {hyper, \"left\"})\n * fullscreen: for the full-screen action (e.g. {hyper, \"f\"})\n\nA configuration example can be:\n```\nlocal hyper = {\"ctrl\", \"alt\", \"cmd\"}\nspoon.MiroWindowsManager:bindHotkeys({\n up = {hyper, \"up\"},\n right = {hyper, \"right\"},\n down = {hyper, \"down\"},\n left = {hyper, \"left\"},\n fullscreen = {hyper, \"f\"}\n})\n```",
"name" : "bindHotkeys",
"stripped_doc" : [
"Binds hotkeys for Miro's Windows Manager"
],
"parameters" : [
" * mapping - A table containing hotkey details for the following items:",
" * up: for the up action (usually {hyper, \"up\"})",
" * right: for the right action (usually {hyper, \"right\"})",
" * down: for the down action (usually {hyper, \"down\"})",
" * left: for the left action (usually {hyper, \"left\"})",
" * fullscreen: for the full-screen action (e.g. {hyper, \"f\"})",
"",
"A configuration example can be:",
"```",
"local hyper = {\"ctrl\", \"alt\", \"cmd\"}",
"spoon.MiroWindowsManager:bindHotkeys({",
" up = {hyper, \"up\"},",
" right = {hyper, \"right\"},",
" down = {hyper, \"down\"},",
" left = {hyper, \"left\"},",
" fullscreen = {hyper, \"f\"}",
"})",
"```"
],
"notes" : [
],
"signature" : "MiroWindowsManager:bindHotkeys()",
"type" : "Method",
"returns" : [
],
"def" : "MiroWindowsManager:bindHotkeys()",
"desc" : "Binds hotkeys for Miro's Windows Manager"
}
],
"Command" : [
],
"items" : [
{
"doc" : "The screen's size using `hs.grid.setGrid()`\nThis parameter is used at the spoon's `:init()`",
"name" : "GRID",
"stripped_doc" : [
"The screen's size using `hs.grid.setGrid()`",
"This parameter is used at the spoon's `:init()`"
],
"parameters" : [
],
"notes" : [
],
"signature" : "MiroWindowsManager.GRID",
"type" : "Variable",
"returns" : [
],
"def" : "MiroWindowsManager.GRID",
"desc" : "The screen's size using `hs.grid.setGrid()`"
},
{
"doc" : "The sizes that the window can have in full-screen. \nThe sizes are expressed as dividend of the entire screen's size.\nFor example `{1, 4\/3, 2}` means that it can be 1\/1 (hence full screen), 3\/4 and 1\/2 of the total screen's size",
"name" : "fullScreenSizes",
"stripped_doc" : [
"The sizes that the window can have in full-screen. ",
"The sizes are expressed as dividend of the entire screen's size.",
"For example `{1, 4\/3, 2}` means that it can be 1\/1 (hence full screen), 3\/4 and 1\/2 of the total screen's size"
],
"parameters" : [
],
"notes" : [
],
"signature" : "MiroWindowsManager.fullScreenSizes",
"type" : "Variable",
"returns" : [
],
"def" : "MiroWindowsManager.fullScreenSizes",
"desc" : "The sizes that the window can have in full-screen."
},
{
"doc" : "The sizes that the window can have. \nThe sizes are expressed as dividend of the entire screen's size.\nFor example `{2, 3, 3\/2}` means that it can be 1\/2, 1\/3 and 2\/3 of the total screen's size",
"name" : "sizes",
"stripped_doc" : [
"The sizes that the window can have. ",
"The sizes are expressed as dividend of the entire screen's size.",
"For example `{2, 3, 3\/2}` means that it can be 1\/2, 1\/3 and 2\/3 of the total screen's size"
],
"parameters" : [
],
"notes" : [
],
"signature" : "MiroWindowsManager.sizes",
"type" : "Variable",
"returns" : [
],
"def" : "MiroWindowsManager.sizes",
"desc" : "The sizes that the window can have."
},
{
"doc" : "Binds hotkeys for Miro's Windows Manager\nParameters:\n * mapping - A table containing hotkey details for the following items:\n * up: for the up action (usually {hyper, \"up\"})\n * right: for the right action (usually {hyper, \"right\"})\n * down: for the down action (usually {hyper, \"down\"})\n * left: for the left action (usually {hyper, \"left\"})\n * fullscreen: for the full-screen action (e.g. {hyper, \"f\"})\n\nA configuration example can be:\n```\nlocal hyper = {\"ctrl\", \"alt\", \"cmd\"}\nspoon.MiroWindowsManager:bindHotkeys({\n up = {hyper, \"up\"},\n right = {hyper, \"right\"},\n down = {hyper, \"down\"},\n left = {hyper, \"left\"},\n fullscreen = {hyper, \"f\"}\n})\n```",
"name" : "bindHotkeys",
"stripped_doc" : [
"Binds hotkeys for Miro's Windows Manager"
],
"parameters" : [
" * mapping - A table containing hotkey details for the following items:",
" * up: for the up action (usually {hyper, \"up\"})",
" * right: for the right action (usually {hyper, \"right\"})",
" * down: for the down action (usually {hyper, \"down\"})",
" * left: for the left action (usually {hyper, \"left\"})",
" * fullscreen: for the full-screen action (e.g. {hyper, \"f\"})",
"",
"A configuration example can be:",
"```",
"local hyper = {\"ctrl\", \"alt\", \"cmd\"}",
"spoon.MiroWindowsManager:bindHotkeys({",
" up = {hyper, \"up\"},",
" right = {hyper, \"right\"},",
" down = {hyper, \"down\"},",
" left = {hyper, \"left\"},",
" fullscreen = {hyper, \"f\"}",
"})",
"```"
],
"notes" : [
],
"signature" : "MiroWindowsManager:bindHotkeys()",
"type" : "Method",
"returns" : [
],
"def" : "MiroWindowsManager:bindHotkeys()",
"desc" : "Binds hotkeys for Miro's Windows Manager"
}
],
"Field" : [
],
"name" : "MiroWindowsManager"
}
]

@ -1,236 +0,0 @@
-- Copyright (c) 2018 Miro Mannino
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this
-- software and associated documentation files (the "Software"), to deal in the Software
-- without restriction, including without limitation the rights to use, copy, modify, merge,
-- publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
-- to whom the Software is furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all copies
-- or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
-- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-- PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
-- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
--- === MiroWindowsManager ===
---
--- With this script you will be able to move the window in halves and in corners using your keyboard and mainly using arrows. You would also be able to resize them by thirds, quarters, or halves.
---
--- Official homepage for more info and documentation: [https://github.com/miromannino/miro-windows-manager](https://github.com/miromannino/miro-windows-manager)
---
--- Download: [https://github.com/miromannino/miro-windows-manager/raw/master/MiroWindowsManager.spoon.zip](https://github.com/miromannino/miro-windows-manager/raw/master/MiroWindowsManager.spoon.zip)
---
local obj={}
obj.__index = obj
-- Metadata
obj.name = "MiroWindowsManager"
obj.version = "1.1"
obj.author = "Miro Mannino <miro.mannino@gmail.com>"
obj.homepage = "https://github.com/miromannino/miro-windows-management"
obj.license = "MIT - https://opensource.org/licenses/MIT"
--- MiroWindowsManager.sizes
--- Variable
--- The sizes that the window can have.
--- The sizes are expressed as dividend of the entire screen's size.
--- For example `{2, 3, 3/2}` means that it can be 1/2, 1/3 and 2/3 of the total screen's size
obj.sizes = {2, 3, 3/2}
--- MiroWindowsManager.fullScreenSizes
--- Variable
--- The sizes that the window can have in full-screen.
--- The sizes are expressed as dividend of the entire screen's size.
--- For example `{1, 4/3, 2}` means that it can be 1/1 (hence full screen), 3/4 and 1/2 of the total screen's size
obj.fullScreenSizes = {1, 4/3, 2}
--- MiroWindowsManager.GRID
--- Variable
--- The screen's size using `hs.grid.setGrid()`
--- This parameter is used at the spoon's `:init()`
obj.GRID = {w = 24, h = 24}
obj._pressed = {
up = false,
down = false,
left = false,
right = false
}
function obj:_nextStep(dim, offs, cb)
if hs.window.focusedWindow() then
local axis = dim == 'w' and 'x' or 'y'
local oppDim = dim == 'w' and 'h' or 'w'
local oppAxis = dim == 'w' and 'y' or 'x'
local win = hs.window.frontmostWindow()
local id = win:id()
local screen = win:screen()
cell = hs.grid.get(win, screen)
local nextSize = self.sizes[1]
for i=1,#self.sizes do
if cell[dim] == self.GRID[dim] / self.sizes[i] and
(cell[axis] + (offs and cell[dim] or 0)) == (offs and self.GRID[dim] or 0)
then
nextSize = self.sizes[(i % #self.sizes) + 1]
break
end
end
cb(cell, nextSize)
if cell[oppAxis] ~= 0 and cell[oppAxis] + cell[oppDim] ~= self.GRID[oppDim] then
cell[oppDim] = self.GRID[oppDim]
cell[oppAxis] = 0
end
hs.grid.set(win, cell, screen)
end
end
function obj:_nextFullScreenStep()
if hs.window.focusedWindow() then
local win = hs.window.frontmostWindow()
local id = win:id()
local screen = win:screen()
cell = hs.grid.get(win, screen)
local nextSize = self.fullScreenSizes[1]
for i=1,#self.fullScreenSizes do
if cell.w == self.GRID.w / self.fullScreenSizes[i] and
cell.h == self.GRID.h / self.fullScreenSizes[i] and
cell.x == (self.GRID.w - self.GRID.w / self.fullScreenSizes[i]) / 2 and
cell.y == (self.GRID.h - self.GRID.h / self.fullScreenSizes[i]) / 2 then
nextSize = self.fullScreenSizes[(i % #self.fullScreenSizes) + 1]
break
end
end
cell.w = self.GRID.w / nextSize
cell.h = self.GRID.h / nextSize
cell.x = (self.GRID.w - self.GRID.w / nextSize) / 2
cell.y = (self.GRID.h - self.GRID.h / nextSize) / 2
hs.grid.set(win, cell, screen)
end
end
function obj:_fullDimension(dim)
if hs.window.focusedWindow() then
local win = hs.window.frontmostWindow()
local id = win:id()
local screen = win:screen()
cell = hs.grid.get(win, screen)
if (dim == 'x') then
cell = '0,0 ' .. self.GRID.w .. 'x' .. self.GRID.h
else
cell[dim] = self.GRID[dim]
cell[dim == 'w' and 'x' or 'y'] = 0
end
hs.grid.set(win, cell, screen)
end
end
--- MiroWindowsManager:bindHotkeys()
--- Method
--- Binds hotkeys for Miro's Windows Manager
--- Parameters:
--- * mapping - A table containing hotkey details for the following items:
--- * up: for the up action (usually {hyper, "up"})
--- * right: for the right action (usually {hyper, "right"})
--- * down: for the down action (usually {hyper, "down"})
--- * left: for the left action (usually {hyper, "left"})
--- * fullscreen: for the full-screen action (e.g. {hyper, "f"})
---
--- A configuration example can be:
--- ```
--- local hyper = {"ctrl", "alt", "cmd"}
--- spoon.MiroWindowsManager:bindHotkeys({
--- up = {hyper, "up"},
--- right = {hyper, "right"},
--- down = {hyper, "down"},
--- left = {hyper, "left"},
--- fullscreen = {hyper, "f"}
--- })
--- ```
function obj:bindHotkeys(mapping)
hs.inspect(mapping)
print("Bind Hotkeys for Miro's Windows Manager")
hs.hotkey.bind(mapping.down[1], mapping.down[2], function ()
self._pressed.down = true
if self._pressed.up then
self:_fullDimension('h')
else
self:_nextStep('h', true, function (cell, nextSize)
cell.y = self.GRID.h - self.GRID.h / nextSize
cell.h = self.GRID.h / nextSize
end)
end
end, function ()
self._pressed.down = false
end)
hs.hotkey.bind(mapping.right[1], mapping.right[2], function ()
self._pressed.right = true
if self._pressed.left then
self:_fullDimension('w')
else
self:_nextStep('w', true, function (cell, nextSize)
cell.x = self.GRID.w - self.GRID.w / nextSize
cell.w = self.GRID.w / nextSize
end)
end
end, function ()
self._pressed.right = false
end)
hs.hotkey.bind(mapping.left[1], mapping.left[2], function ()
self._pressed.left = true
if self._pressed.right then
self:_fullDimension('w')
else
self:_nextStep('w', false, function (cell, nextSize)
cell.x = 0
cell.w = self.GRID.w / nextSize
end)
end
end, function ()
self._pressed.left = false
end)
hs.hotkey.bind(mapping.up[1], mapping.up[2], function ()
self._pressed.up = true
if self._pressed.down then
self:_fullDimension('h')
else
self:_nextStep('h', false, function (cell, nextSize)
cell.y = 0
cell.h = self.GRID.h / nextSize
end)
end
end, function ()
self._pressed.up = false
end)
hs.hotkey.bind(mapping.fullscreen[1], mapping.fullscreen[2], function ()
self:_nextFullScreenStep()
end)
end
function obj:init()
print("Initializing Miro's Windows Manager")
hs.grid.setGrid(obj.GRID.w .. 'x' .. obj.GRID.h)
hs.grid.MARGINX = 0
hs.grid.MARGINY = 0
end
return obj

@ -1,90 +0,0 @@
[
{
"Command": [],
"Constant": [],
"Constructor": [],
"Deprecated": [],
"Field": [],
"Function": [],
"Method": [
{
"def": "ReloadConfiguration:bindHotkeys(mapping)",
"desc": "Binds hotkeys for ReloadConfiguration",
"doc": "Binds hotkeys for ReloadConfiguration\n\nParameters:\n * mapping - A table containing hotkey modifier/key details for the following items:\n * reloadConfiguration - This will cause the configuration to be reloaded",
"name": "bindHotkeys",
"parameters": [
" * mapping - A table containing hotkey modifier/key details for the following items:",
" * reloadConfiguration - This will cause the configuration to be reloaded"
],
"signature": "ReloadConfiguration:bindHotkeys(mapping)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "ReloadConfiguration:start()",
"desc": "Start ReloadConfiguration",
"doc": "Start ReloadConfiguration\n\nParameters:\n * None",
"name": "start",
"parameters": [
" * None"
],
"signature": "ReloadConfiguration:start()",
"stripped_doc": "",
"type": "Method"
}
],
"Variable": [
{
"def": "ReloadConfiguration.watch_paths",
"desc": "List of directories to watch for changes, defaults to hs.configdir",
"doc": "List of directories to watch for changes, defaults to hs.configdir",
"name": "watch_paths",
"signature": "ReloadConfiguration.watch_paths",
"stripped_doc": "",
"type": "Variable"
}
],
"desc": "Adds a hotkey to reload the hammerspoon configuration, and a pathwatcher to automatically reload on changes.",
"doc": "Adds a hotkey to reload the hammerspoon configuration, and a pathwatcher to automatically reload on changes.\n\nDownload: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/ReloadConfiguration.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/ReloadConfiguration.spoon.zip)",
"items": [
{
"def": "ReloadConfiguration:bindHotkeys(mapping)",
"desc": "Binds hotkeys for ReloadConfiguration",
"doc": "Binds hotkeys for ReloadConfiguration\n\nParameters:\n * mapping - A table containing hotkey modifier/key details for the following items:\n * reloadConfiguration - This will cause the configuration to be reloaded",
"name": "bindHotkeys",
"parameters": [
" * mapping - A table containing hotkey modifier/key details for the following items:",
" * reloadConfiguration - This will cause the configuration to be reloaded"
],
"signature": "ReloadConfiguration:bindHotkeys(mapping)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "ReloadConfiguration:start()",
"desc": "Start ReloadConfiguration",
"doc": "Start ReloadConfiguration\n\nParameters:\n * None",
"name": "start",
"parameters": [
" * None"
],
"signature": "ReloadConfiguration:start()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "ReloadConfiguration.watch_paths",
"desc": "List of directories to watch for changes, defaults to hs.configdir",
"doc": "List of directories to watch for changes, defaults to hs.configdir",
"name": "watch_paths",
"signature": "ReloadConfiguration.watch_paths",
"stripped_doc": "",
"type": "Variable"
}
],
"name": "ReloadConfiguration",
"stripped_doc": "\nDownload: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/ReloadConfiguration.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/ReloadConfiguration.spoon.zip)",
"submodules": [],
"type": "Module"
}
]

@ -1,49 +0,0 @@
--- === ReloadConfiguration ===
---
--- Adds a hotkey to reload the hammerspoon configuration, and a pathwatcher to automatically reload on changes.
---
--- Download: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/ReloadConfiguration.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/ReloadConfiguration.spoon.zip)
local obj = {}
obj.__index = obj
-- Metadata
obj.name = "ReloadConfiguration"
obj.version = "1.0"
obj.author = "Jon Lorusso <jonlorusso@gmail.com>"
obj.homepage = "https://github.com/Hammerspoon/Spoons"
obj.license = "MIT - https://opensource.org/licenses/MIT"
--- ReloadConfiguration.watch_paths
--- Variable
--- List of directories to watch for changes, defaults to hs.configdir
obj.watch_paths = { hs.configdir }
--- ReloadConfiguration:bindHotkeys(mapping)
--- Method
--- Binds hotkeys for ReloadConfiguration
---
--- Parameters:
--- * mapping - A table containing hotkey modifier/key details for the following items:
--- * reloadConfiguration - This will cause the configuration to be reloaded
function obj:bindHotkeys(mapping)
local def = { reloadConfiguration = hs.fnutils.partial(hs.reload, self) }
hs.spoons.bindHotkeysToSpec(def, mapping)
end
--- ReloadConfiguration:start()
--- Method
--- Start ReloadConfiguration
---
--- Parameters:
--- * None
function obj:start()
self.watchers = {}
for _,dir in pairs(self.watch_paths) do
self.watchers[dir] = hs.pathwatcher.new(dir, hs.reload):start()
end
return self
end
return obj

@ -0,0 +1,478 @@
[
{
"Command": [],
"Constant": [],
"Constructor": [],
"Deprecated": [],
"Field": [],
"Function": [],
"Method": [
{
"def": "SpoonInstall:andUse(name, arg)",
"desc": "Declaratively install, load and configure a Spoon",
"doc": "Declaratively install, load and configure a Spoon\n\nParameters:\n * name - the name of the Spoon to install (without the `.spoon` extension). If the Spoon is already installed, it will be loaded using `hs.loadSpoon()`. If it is not installed, it will be installed using `SpoonInstall:asyncInstallSpoonFromRepo()` and then loaded.\n * arg - if provided, can be used to specify the configuration of the Spoon. The following keys are recognized (all are optional):\n * repo - repository from where the Spoon should be installed if not present in the system, as defined in `SpoonInstall.repos`. Defaults to `\"default\"`.\n * config - a table containing variables to be stored in the Spoon object to configure it. For example, `config = { answer = 42 }` will result in `spoon.<LoadedSpoon>.answer` being set to 42.\n * hotkeys - a table containing hotkey bindings. If provided, will be passed as-is to the Spoon's `bindHotkeys()` method. The special string `\"default\"` can be given to use the Spoons `defaultHotkeys` variable, if it exists.\n * fn - a function which will be called with the freshly-loaded Spoon object as its first argument.\n * loglevel - if the Spoon has a variable called `logger`, its `setLogLevel()` method will be called with this value.\n * start - if `true`, call the Spoon's `start()` method after configuring everything else.\n * disable - if `true`, do nothing. Easier than commenting it out when you want to temporarily disable a spoon.\n\nReturns:\n * None",
"name": "andUse",
"parameters": [
" * name - the name of the Spoon to install (without the `.spoon` extension). If the Spoon is already installed, it will be loaded using `hs.loadSpoon()`. If it is not installed, it will be installed using `SpoonInstall:asyncInstallSpoonFromRepo()` and then loaded.",
" * arg - if provided, can be used to specify the configuration of the Spoon. The following keys are recognized (all are optional):",
" * repo - repository from where the Spoon should be installed if not present in the system, as defined in `SpoonInstall.repos`. Defaults to `\"default\"`.",
" * config - a table containing variables to be stored in the Spoon object to configure it. For example, `config = { answer = 42 }` will result in `spoon.<LoadedSpoon>.answer` being set to 42.",
" * hotkeys - a table containing hotkey bindings. If provided, will be passed as-is to the Spoon's `bindHotkeys()` method. The special string `\"default\"` can be given to use the Spoons `defaultHotkeys` variable, if it exists.",
" * fn - a function which will be called with the freshly-loaded Spoon object as its first argument.",
" * loglevel - if the Spoon has a variable called `logger`, its `setLogLevel()` method will be called with this value.",
" * start - if `true`, call the Spoon's `start()` method after configuring everything else.",
" * disable - if `true`, do nothing. Easier than commenting it out when you want to temporarily disable a spoon."
],
"returns": [
" * None"
],
"signature": "SpoonInstall:andUse(name, arg)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:asyncInstallSpoonFromRepo(name, repo, callback)",
"desc": "Asynchronously install a Spoon from a registered repository",
"doc": "Asynchronously install a Spoon from a registered repository\n\nParameters:\n * name - Name of the Spoon to install.\n * repo - Name of the repository to use. Defaults to `\"default\"`\n * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:\n * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file\n * success - boolean indicating whether the installation was successful\n\nReturns:\n * `true` if the installation was correctly initiated (i.e. the repo and spoon name were correct), `false` otherwise.",
"name": "asyncInstallSpoonFromRepo",
"parameters": [
" * name - Name of the Spoon to install.",
" * repo - Name of the repository to use. Defaults to `\"default\"`",
" * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:",
" * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file",
" * success - boolean indicating whether the installation was successful"
],
"returns": [
" * `true` if the installation was correctly initiated (i.e. the repo and spoon name were correct), `false` otherwise."
],
"signature": "SpoonInstall:asyncInstallSpoonFromRepo(name, repo, callback)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:asyncInstallSpoonFromZipURL(url, callback)",
"desc": "Asynchronously download a Spoon zip file and install it.",
"doc": "Asynchronously download a Spoon zip file and install it.\n\nParameters:\n * url - URL of the zip file to install.\n * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:\n * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file\n * success - boolean indicating whether the installation was successful\n\nReturns:\n * `true` if the installation was correctly initiated (i.e. the URL is valid), `false` otherwise",
"name": "asyncInstallSpoonFromZipURL",
"parameters": [
" * url - URL of the zip file to install.",
" * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:",
" * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file",
" * success - boolean indicating whether the installation was successful"
],
"returns": [
" * `true` if the installation was correctly initiated (i.e. the URL is valid), `false` otherwise"
],
"signature": "SpoonInstall:asyncInstallSpoonFromZipURL(url, callback)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:asyncUpdateAllRepos()",
"desc": "Asynchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`",
"doc": "Asynchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`\n\nParameters:\n * None\n\nReturns:\n * None\n\nNotes:\n * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.",
"name": "asyncUpdateAllRepos",
"notes": [
" * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions."
],
"parameters": [
" * None"
],
"returns": [
" * None"
],
"signature": "SpoonInstall:asyncUpdateAllRepos()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:asyncUpdateRepo(repo, callback)",
"desc": "Asynchronously fetch the information about the contents of a Spoon repository",
"doc": "Asynchronously fetch the information about the contents of a Spoon repository\n\nParameters:\n * repo - name of the repository to update. Defaults to `\"default\"`.\n * callback - if given, a function to be called after the update finishes (also if it fails). The function will receive the following arguments:\n * repo - name of the repository\n * success - boolean indicating whether the update succeeded\n\nReturns:\n * `true` if the update was correctly initiated (i.e. the repo name is valid), `nil` otherwise\n\nNotes:\n * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.",
"name": "asyncUpdateRepo",
"notes": [
" * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions."
],
"parameters": [
" * repo - name of the repository to update. Defaults to `\"default\"`.",
" * callback - if given, a function to be called after the update finishes (also if it fails). The function will receive the following arguments:",
" * repo - name of the repository",
" * success - boolean indicating whether the update succeeded"
],
"returns": [
" * `true` if the update was correctly initiated (i.e. the repo name is valid), `nil` otherwise"
],
"signature": "SpoonInstall:asyncUpdateRepo(repo, callback)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:installSpoonFromRepo(name, repo)",
"desc": "Synchronously install a Spoon from a registered repository",
"doc": "Synchronously install a Spoon from a registered repository\n\nParameters:\n * name = Name of the Spoon to install.\n * repo - Name of the repository to use. Defaults to `\"default\"`\n\nReturns:\n * `true` if the installation was successful, `nil` otherwise.",
"name": "installSpoonFromRepo",
"parameters": [
" * name = Name of the Spoon to install.",
" * repo - Name of the repository to use. Defaults to `\"default\"`"
],
"returns": [
" * `true` if the installation was successful, `nil` otherwise."
],
"signature": "SpoonInstall:installSpoonFromRepo(name, repo)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:installSpoonFromZipURL(url)",
"desc": "Synchronously download a Spoon zip file and install it.",
"doc": "Synchronously download a Spoon zip file and install it.\n\nParameters:\n * url - URL of the zip file to install.\n\nReturns:\n * `true` if the installation was successful, `nil` otherwise",
"name": "installSpoonFromZipURL",
"parameters": [
" * url - URL of the zip file to install."
],
"returns": [
" * `true` if the installation was successful, `nil` otherwise"
],
"signature": "SpoonInstall:installSpoonFromZipURL(url)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:repolist()",
"desc": "Return a sorted list of registered Spoon repositories",
"doc": "Return a sorted list of registered Spoon repositories\n\nParameters:\n * None\n\nReturns:\n * Table containing a list of strings with the repository identifiers",
"name": "repolist",
"parameters": [
" * None"
],
"returns": [
" * Table containing a list of strings with the repository identifiers"
],
"signature": "SpoonInstall:repolist()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:search(pat)",
"desc": "Search repositories for a pattern",
"doc": "Search repositories for a pattern\n\nParameters:\n * pat - Lua pattern that will be matched against the name and description of each spoon in the registered repositories. All text is converted to lowercase before searching it, so you can use all-lowercase in your pattern.\n\nReturns:\n * Table containing a list of matching entries. Each entry is a table with the following keys:\n * name - Spoon name\n * desc - description of the spoon\n * repo - identifier in the repository where the match was found",
"name": "search",
"parameters": [
" * pat - Lua pattern that will be matched against the name and description of each spoon in the registered repositories. All text is converted to lowercase before searching it, so you can use all-lowercase in your pattern."
],
"returns": [
" * Table containing a list of matching entries. Each entry is a table with the following keys:",
" * name - Spoon name",
" * desc - description of the spoon",
" * repo - identifier in the repository where the match was found"
],
"signature": "SpoonInstall:search(pat)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:updateAllRepos()",
"desc": "Synchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`",
"doc": "Synchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`\n\nParameters:\n * None\n\nReturns:\n * None\n\nNotes:\n * This is a synchronous call, which means Hammerspoon will be blocked until it finishes.\n * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.",
"name": "updateAllRepos",
"notes": [
" * This is a synchronous call, which means Hammerspoon will be blocked until it finishes.",
" * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions."
],
"parameters": [
" * None"
],
"returns": [
" * None"
],
"signature": "SpoonInstall:updateAllRepos()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:updateRepo(repo)",
"desc": "Synchronously fetch the information about the contents of a Spoon repository",
"doc": "Synchronously fetch the information about the contents of a Spoon repository\n\nParameters:\n * repo - name of the repository to update. Defaults to `\"default\"`.\n\nReturns:\n * `true` if the update was successful, `nil` otherwise\n\nNotes:\n * This is a synchronous call, which means Hammerspoon will be blocked until it finishes. For use in your configuration files, it's advisable to use `SpoonInstall.asyncUpdateRepo()` instead.\n * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.",
"name": "updateRepo",
"notes": [
" * This is a synchronous call, which means Hammerspoon will be blocked until it finishes. For use in your configuration files, it's advisable to use `SpoonInstall.asyncUpdateRepo()` instead.",
" * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions."
],
"parameters": [
" * repo - name of the repository to update. Defaults to `\"default\"`."
],
"returns": [
" * `true` if the update was successful, `nil` otherwise"
],
"signature": "SpoonInstall:updateRepo(repo)",
"stripped_doc": "",
"type": "Method"
}
],
"Variable": [
{
"def": "SpoonInstall.logger",
"desc": "Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.",
"doc": "Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.",
"name": "logger",
"signature": "SpoonInstall.logger",
"stripped_doc": "",
"type": "Variable"
},
{
"def": "SpoonInstall.repos",
"desc": "Table containing the list of available Spoon repositories. The key",
"doc": "Table containing the list of available Spoon repositories. The key\nof each entry is an identifier for the repository, and its value\nis a table with the following entries:\n * desc - Human-readable description for the repository\n * branch - Active git branch for the Spoon files\n * url - Base URL for the repository. For now the repository is assumed to be hosted in GitHub, and the URL should be the main base URL of the repository. Repository metadata needs to be stored under `docs/docs.json`, and the Spoon zip files need to be stored under `Spoons/`.\n\nDefault value:\n```\n{\n default = {\n url = \"https://github.com/Hammerspoon/Spoons\",\n desc = \"Main Hammerspoon Spoon repository\",\n branch = \"master\",\n }\n}\n```",
"name": "repos",
"signature": "SpoonInstall.repos",
"stripped_doc": "of each entry is an identifier for the repository, and its value\nis a table with the following entries:\n * desc - Human-readable description for the repository\n * branch - Active git branch for the Spoon files\n * url - Base URL for the repository. For now the repository is assumed to be hosted in GitHub, and the URL should be the main base URL of the repository. Repository metadata needs to be stored under `docs/docs.json`, and the Spoon zip files need to be stored under `Spoons/`.\nDefault value:\n```\n{\n default = {\n url = \"https://github.com/Hammerspoon/Spoons\",\n desc = \"Main Hammerspoon Spoon repository\",\n branch = \"master\",\n }\n}\n```",
"type": "Variable"
},
{
"def": "SpoonInstall.use_syncinstall",
"desc": "If `true`, `andUse()` will update repos and install packages synchronously. Defaults to `false`.",
"doc": "If `true`, `andUse()` will update repos and install packages synchronously. Defaults to `false`.\n\nKeep in mind that if you set this to `true`, Hammerspoon will\nblock until all missing Spoons are installed, but the notifications\nwill happen at a more \"human readable\" rate.",
"name": "use_syncinstall",
"signature": "SpoonInstall.use_syncinstall",
"stripped_doc": "Keep in mind that if you set this to `true`, Hammerspoon will\nblock until all missing Spoons are installed, but the notifications\nwill happen at a more \"human readable\" rate.",
"type": "Variable"
}
],
"desc": "Install and manage Spoons and Spoon repositories",
"doc": "Install and manage Spoons and Spoon repositories\n\nDownload: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip)",
"items": [
{
"def": "SpoonInstall:andUse(name, arg)",
"desc": "Declaratively install, load and configure a Spoon",
"doc": "Declaratively install, load and configure a Spoon\n\nParameters:\n * name - the name of the Spoon to install (without the `.spoon` extension). If the Spoon is already installed, it will be loaded using `hs.loadSpoon()`. If it is not installed, it will be installed using `SpoonInstall:asyncInstallSpoonFromRepo()` and then loaded.\n * arg - if provided, can be used to specify the configuration of the Spoon. The following keys are recognized (all are optional):\n * repo - repository from where the Spoon should be installed if not present in the system, as defined in `SpoonInstall.repos`. Defaults to `\"default\"`.\n * config - a table containing variables to be stored in the Spoon object to configure it. For example, `config = { answer = 42 }` will result in `spoon.<LoadedSpoon>.answer` being set to 42.\n * hotkeys - a table containing hotkey bindings. If provided, will be passed as-is to the Spoon's `bindHotkeys()` method. The special string `\"default\"` can be given to use the Spoons `defaultHotkeys` variable, if it exists.\n * fn - a function which will be called with the freshly-loaded Spoon object as its first argument.\n * loglevel - if the Spoon has a variable called `logger`, its `setLogLevel()` method will be called with this value.\n * start - if `true`, call the Spoon's `start()` method after configuring everything else.\n * disable - if `true`, do nothing. Easier than commenting it out when you want to temporarily disable a spoon.\n\nReturns:\n * None",
"name": "andUse",
"parameters": [
" * name - the name of the Spoon to install (without the `.spoon` extension). If the Spoon is already installed, it will be loaded using `hs.loadSpoon()`. If it is not installed, it will be installed using `SpoonInstall:asyncInstallSpoonFromRepo()` and then loaded.",
" * arg - if provided, can be used to specify the configuration of the Spoon. The following keys are recognized (all are optional):",
" * repo - repository from where the Spoon should be installed if not present in the system, as defined in `SpoonInstall.repos`. Defaults to `\"default\"`.",
" * config - a table containing variables to be stored in the Spoon object to configure it. For example, `config = { answer = 42 }` will result in `spoon.<LoadedSpoon>.answer` being set to 42.",
" * hotkeys - a table containing hotkey bindings. If provided, will be passed as-is to the Spoon's `bindHotkeys()` method. The special string `\"default\"` can be given to use the Spoons `defaultHotkeys` variable, if it exists.",
" * fn - a function which will be called with the freshly-loaded Spoon object as its first argument.",
" * loglevel - if the Spoon has a variable called `logger`, its `setLogLevel()` method will be called with this value.",
" * start - if `true`, call the Spoon's `start()` method after configuring everything else.",
" * disable - if `true`, do nothing. Easier than commenting it out when you want to temporarily disable a spoon."
],
"returns": [
" * None"
],
"signature": "SpoonInstall:andUse(name, arg)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:asyncInstallSpoonFromRepo(name, repo, callback)",
"desc": "Asynchronously install a Spoon from a registered repository",
"doc": "Asynchronously install a Spoon from a registered repository\n\nParameters:\n * name - Name of the Spoon to install.\n * repo - Name of the repository to use. Defaults to `\"default\"`\n * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:\n * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file\n * success - boolean indicating whether the installation was successful\n\nReturns:\n * `true` if the installation was correctly initiated (i.e. the repo and spoon name were correct), `false` otherwise.",
"name": "asyncInstallSpoonFromRepo",
"parameters": [
" * name - Name of the Spoon to install.",
" * repo - Name of the repository to use. Defaults to `\"default\"`",
" * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:",
" * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file",
" * success - boolean indicating whether the installation was successful"
],
"returns": [
" * `true` if the installation was correctly initiated (i.e. the repo and spoon name were correct), `false` otherwise."
],
"signature": "SpoonInstall:asyncInstallSpoonFromRepo(name, repo, callback)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:asyncInstallSpoonFromZipURL(url, callback)",
"desc": "Asynchronously download a Spoon zip file and install it.",
"doc": "Asynchronously download a Spoon zip file and install it.\n\nParameters:\n * url - URL of the zip file to install.\n * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:\n * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file\n * success - boolean indicating whether the installation was successful\n\nReturns:\n * `true` if the installation was correctly initiated (i.e. the URL is valid), `false` otherwise",
"name": "asyncInstallSpoonFromZipURL",
"parameters": [
" * url - URL of the zip file to install.",
" * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:",
" * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file",
" * success - boolean indicating whether the installation was successful"
],
"returns": [
" * `true` if the installation was correctly initiated (i.e. the URL is valid), `false` otherwise"
],
"signature": "SpoonInstall:asyncInstallSpoonFromZipURL(url, callback)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:asyncUpdateAllRepos()",
"desc": "Asynchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`",
"doc": "Asynchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`\n\nParameters:\n * None\n\nReturns:\n * None\n\nNotes:\n * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.",
"name": "asyncUpdateAllRepos",
"notes": [
" * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions."
],
"parameters": [
" * None"
],
"returns": [
" * None"
],
"signature": "SpoonInstall:asyncUpdateAllRepos()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:asyncUpdateRepo(repo, callback)",
"desc": "Asynchronously fetch the information about the contents of a Spoon repository",
"doc": "Asynchronously fetch the information about the contents of a Spoon repository\n\nParameters:\n * repo - name of the repository to update. Defaults to `\"default\"`.\n * callback - if given, a function to be called after the update finishes (also if it fails). The function will receive the following arguments:\n * repo - name of the repository\n * success - boolean indicating whether the update succeeded\n\nReturns:\n * `true` if the update was correctly initiated (i.e. the repo name is valid), `nil` otherwise\n\nNotes:\n * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.",
"name": "asyncUpdateRepo",
"notes": [
" * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions."
],
"parameters": [
" * repo - name of the repository to update. Defaults to `\"default\"`.",
" * callback - if given, a function to be called after the update finishes (also if it fails). The function will receive the following arguments:",
" * repo - name of the repository",
" * success - boolean indicating whether the update succeeded"
],
"returns": [
" * `true` if the update was correctly initiated (i.e. the repo name is valid), `nil` otherwise"
],
"signature": "SpoonInstall:asyncUpdateRepo(repo, callback)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:installSpoonFromRepo(name, repo)",
"desc": "Synchronously install a Spoon from a registered repository",
"doc": "Synchronously install a Spoon from a registered repository\n\nParameters:\n * name = Name of the Spoon to install.\n * repo - Name of the repository to use. Defaults to `\"default\"`\n\nReturns:\n * `true` if the installation was successful, `nil` otherwise.",
"name": "installSpoonFromRepo",
"parameters": [
" * name = Name of the Spoon to install.",
" * repo - Name of the repository to use. Defaults to `\"default\"`"
],
"returns": [
" * `true` if the installation was successful, `nil` otherwise."
],
"signature": "SpoonInstall:installSpoonFromRepo(name, repo)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:installSpoonFromZipURL(url)",
"desc": "Synchronously download a Spoon zip file and install it.",
"doc": "Synchronously download a Spoon zip file and install it.\n\nParameters:\n * url - URL of the zip file to install.\n\nReturns:\n * `true` if the installation was successful, `nil` otherwise",
"name": "installSpoonFromZipURL",
"parameters": [
" * url - URL of the zip file to install."
],
"returns": [
" * `true` if the installation was successful, `nil` otherwise"
],
"signature": "SpoonInstall:installSpoonFromZipURL(url)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall.logger",
"desc": "Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.",
"doc": "Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.",
"name": "logger",
"signature": "SpoonInstall.logger",
"stripped_doc": "",
"type": "Variable"
},
{
"def": "SpoonInstall:repolist()",
"desc": "Return a sorted list of registered Spoon repositories",
"doc": "Return a sorted list of registered Spoon repositories\n\nParameters:\n * None\n\nReturns:\n * Table containing a list of strings with the repository identifiers",
"name": "repolist",
"parameters": [
" * None"
],
"returns": [
" * Table containing a list of strings with the repository identifiers"
],
"signature": "SpoonInstall:repolist()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall.repos",
"desc": "Table containing the list of available Spoon repositories. The key",
"doc": "Table containing the list of available Spoon repositories. The key\nof each entry is an identifier for the repository, and its value\nis a table with the following entries:\n * desc - Human-readable description for the repository\n * branch - Active git branch for the Spoon files\n * url - Base URL for the repository. For now the repository is assumed to be hosted in GitHub, and the URL should be the main base URL of the repository. Repository metadata needs to be stored under `docs/docs.json`, and the Spoon zip files need to be stored under `Spoons/`.\n\nDefault value:\n```\n{\n default = {\n url = \"https://github.com/Hammerspoon/Spoons\",\n desc = \"Main Hammerspoon Spoon repository\",\n branch = \"master\",\n }\n}\n```",
"name": "repos",
"signature": "SpoonInstall.repos",
"stripped_doc": "of each entry is an identifier for the repository, and its value\nis a table with the following entries:\n * desc - Human-readable description for the repository\n * branch - Active git branch for the Spoon files\n * url - Base URL for the repository. For now the repository is assumed to be hosted in GitHub, and the URL should be the main base URL of the repository. Repository metadata needs to be stored under `docs/docs.json`, and the Spoon zip files need to be stored under `Spoons/`.\nDefault value:\n```\n{\n default = {\n url = \"https://github.com/Hammerspoon/Spoons\",\n desc = \"Main Hammerspoon Spoon repository\",\n branch = \"master\",\n }\n}\n```",
"type": "Variable"
},
{
"def": "SpoonInstall:search(pat)",
"desc": "Search repositories for a pattern",
"doc": "Search repositories for a pattern\n\nParameters:\n * pat - Lua pattern that will be matched against the name and description of each spoon in the registered repositories. All text is converted to lowercase before searching it, so you can use all-lowercase in your pattern.\n\nReturns:\n * Table containing a list of matching entries. Each entry is a table with the following keys:\n * name - Spoon name\n * desc - description of the spoon\n * repo - identifier in the repository where the match was found",
"name": "search",
"parameters": [
" * pat - Lua pattern that will be matched against the name and description of each spoon in the registered repositories. All text is converted to lowercase before searching it, so you can use all-lowercase in your pattern."
],
"returns": [
" * Table containing a list of matching entries. Each entry is a table with the following keys:",
" * name - Spoon name",
" * desc - description of the spoon",
" * repo - identifier in the repository where the match was found"
],
"signature": "SpoonInstall:search(pat)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:updateAllRepos()",
"desc": "Synchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`",
"doc": "Synchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`\n\nParameters:\n * None\n\nReturns:\n * None\n\nNotes:\n * This is a synchronous call, which means Hammerspoon will be blocked until it finishes.\n * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.",
"name": "updateAllRepos",
"notes": [
" * This is a synchronous call, which means Hammerspoon will be blocked until it finishes.",
" * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions."
],
"parameters": [
" * None"
],
"returns": [
" * None"
],
"signature": "SpoonInstall:updateAllRepos()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall:updateRepo(repo)",
"desc": "Synchronously fetch the information about the contents of a Spoon repository",
"doc": "Synchronously fetch the information about the contents of a Spoon repository\n\nParameters:\n * repo - name of the repository to update. Defaults to `\"default\"`.\n\nReturns:\n * `true` if the update was successful, `nil` otherwise\n\nNotes:\n * This is a synchronous call, which means Hammerspoon will be blocked until it finishes. For use in your configuration files, it's advisable to use `SpoonInstall.asyncUpdateRepo()` instead.\n * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.",
"name": "updateRepo",
"notes": [
" * This is a synchronous call, which means Hammerspoon will be blocked until it finishes. For use in your configuration files, it's advisable to use `SpoonInstall.asyncUpdateRepo()` instead.",
" * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions."
],
"parameters": [
" * repo - name of the repository to update. Defaults to `\"default\"`."
],
"returns": [
" * `true` if the update was successful, `nil` otherwise"
],
"signature": "SpoonInstall:updateRepo(repo)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "SpoonInstall.use_syncinstall",
"desc": "If `true`, `andUse()` will update repos and install packages synchronously. Defaults to `false`.",
"doc": "If `true`, `andUse()` will update repos and install packages synchronously. Defaults to `false`.\n\nKeep in mind that if you set this to `true`, Hammerspoon will\nblock until all missing Spoons are installed, but the notifications\nwill happen at a more \"human readable\" rate.",
"name": "use_syncinstall",
"signature": "SpoonInstall.use_syncinstall",
"stripped_doc": "Keep in mind that if you set this to `true`, Hammerspoon will\nblock until all missing Spoons are installed, but the notifications\nwill happen at a more \"human readable\" rate.",
"type": "Variable"
}
],
"name": "SpoonInstall",
"stripped_doc": "\nDownload: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip)",
"submodules": [],
"type": "Module"
}
]

@ -0,0 +1,447 @@
--- === SpoonInstall ===
---
--- Install and manage Spoons and Spoon repositories
---
--- Download: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip)
local obj={}
obj.__index = obj
-- Metadata
obj.name = "SpoonInstall"
obj.version = "0.1"
obj.author = "Diego Zamboni <diego@zzamboni.org>"
obj.homepage = "https://github.com/Hammerspoon/Spoons"
obj.license = "MIT - https://opensource.org/licenses/MIT"
--- SpoonInstall.logger
--- Variable
--- Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.
obj.logger = hs.logger.new('SpoonInstall')
--- SpoonInstall.repos
--- Variable
--- Table containing the list of available Spoon repositories. The key
--- of each entry is an identifier for the repository, and its value
--- is a table with the following entries:
--- * desc - Human-readable description for the repository
--- * branch - Active git branch for the Spoon files
--- * url - Base URL for the repository. For now the repository is assumed to be hosted in GitHub, and the URL should be the main base URL of the repository. Repository metadata needs to be stored under `docs/docs.json`, and the Spoon zip files need to be stored under `Spoons/`.
---
--- Default value:
--- ```
--- {
--- default = {
--- url = "https://github.com/Hammerspoon/Spoons",
--- desc = "Main Hammerspoon Spoon repository",
--- branch = "master",
--- }
--- }
--- ```
obj.repos = {
default = {
url = "https://github.com/Hammerspoon/Spoons",
desc = "Main Hammerspoon Spoon repository",
branch = "master",
}
}
--- SpoonInstall.use_syncinstall
--- Variable
--- If `true`, `andUse()` will update repos and install packages synchronously. Defaults to `false`.
---
--- Keep in mind that if you set this to `true`, Hammerspoon will
--- block until all missing Spoons are installed, but the notifications
--- will happen at a more "human readable" rate.
obj.use_syncinstall = false
-- Execute a command and return its output with trailing EOLs trimmed. If the command fails, an error message is logged.
local function _x(cmd, errfmt, ...)
local output, status = hs.execute(cmd)
if status then
local trimstr = string.gsub(output, "\n*$", "")
return trimstr
else
obj.logger.ef(errfmt, ...)
return nil
end
end
-- --------------------------------------------------------------------
-- Spoon repository management
-- Internal callback to process and store the data from docs.json about a repository
-- callback is called with repo as arguments, only if the call is successful
function obj:_storeRepoJSON(repo, callback, status, body, hdrs)
local success=nil
if (status < 100) or (status >= 400) then
self.logger.ef("Error fetching JSON data for repository '%s'. Error code %d: %s", repo, status, body or "<no error message>")
else
local json = hs.json.decode(body)
if json then
self.repos[repo].data = {}
for i,v in ipairs(json) do
v.download_url = self.repos[repo].download_base_url .. v.name .. ".spoon.zip"
self.repos[repo].data[v.name] = v
end
self.logger.df("Updated JSON data for repository '%s'", repo)
success=true
else
self.logger.ef("Invalid JSON received for repository '%s': %s", repo, body)
end
end
if callback then
callback(repo, success)
end
return success
end
-- Internal function to return the URL of the docs.json file based on the URL of a GitHub repo
function obj:_build_repo_json_url(repo)
if self.repos[repo] and self.repos[repo].url then
local branch = self.repos[repo].branch or "master"
self.repos[repo].json_url = string.gsub(self.repos[repo].url, "/$", "") .. "/raw/"..branch.."/docs/docs.json"
self.repos[repo].download_base_url = string.gsub(self.repos[repo].url, "/$", "") .. "/raw/"..branch.."/Spoons/"
return true
else
self.logger.ef("Invalid or unknown repository '%s'", repo)
return nil
end
end
--- SpoonInstall:asyncUpdateRepo(repo, callback)
--- Method
--- Asynchronously fetch the information about the contents of a Spoon repository
---
--- Parameters:
--- * repo - name of the repository to update. Defaults to `"default"`.
--- * callback - if given, a function to be called after the update finishes (also if it fails). The function will receive the following arguments:
--- * repo - name of the repository
--- * success - boolean indicating whether the update succeeded
---
--- Returns:
--- * `true` if the update was correctly initiated (i.e. the repo name is valid), `nil` otherwise
---
--- Notes:
--- * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.
function obj:asyncUpdateRepo(repo, callback)
if not repo then repo = 'default' end
if self:_build_repo_json_url(repo) then
hs.http.asyncGet(self.repos[repo].json_url, nil, hs.fnutils.partial(self._storeRepoJSON, self, repo, callback))
return true
else
return nil
end
end
--- SpoonInstall:updateRepo(repo)
--- Method
--- Synchronously fetch the information about the contents of a Spoon repository
---
--- Parameters:
--- * repo - name of the repository to update. Defaults to `"default"`.
---
--- Returns:
--- * `true` if the update was successful, `nil` otherwise
---
--- Notes:
--- * This is a synchronous call, which means Hammerspoon will be blocked until it finishes. For use in your configuration files, it's advisable to use `SpoonInstall.asyncUpdateRepo()` instead.
--- * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.
function obj:updateRepo(repo)
if not repo then repo = 'default' end
if self:_build_repo_json_url(repo) then
local a,b,c = hs.http.get(self.repos[repo].json_url)
return self:_storeRepoJSON(repo, nil, a, b, c)
else
return nil
end
end
--- SpoonInstall:asyncUpdateAllRepos()
--- Method
--- Asynchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
---
--- Notes:
--- * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.
function obj:asyncUpdateAllRepos()
for k,v in pairs(self.repos) do
self:asyncUpdateRepo(k)
end
end
--- SpoonInstall:updateAllRepos()
--- Method
--- Synchronously fetch the information about the contents of all Spoon repositories registered in `SpoonInstall.repos`
---
--- Parameters:
--- * None
---
--- Returns:
--- * None
---
--- Notes:
--- * This is a synchronous call, which means Hammerspoon will be blocked until it finishes.
--- * For now, the repository data is not persisted, so you need to update it after every restart if you want to use any of the install functions.
function obj:updateAllRepos()
for k,v in pairs(self.repos) do
self:updateRepo(k)
end
end
--- SpoonInstall:repolist()
--- Method
--- Return a sorted list of registered Spoon repositories
---
--- Parameters:
--- * None
---
--- Returns:
--- * Table containing a list of strings with the repository identifiers
function obj:repolist()
local keys={}
-- Create sorted list of keys
for k,v in pairs(self.repos) do table.insert(keys, k) end
table.sort(keys)
return keys
end
--- SpoonInstall:search(pat)
--- Method
--- Search repositories for a pattern
---
--- Parameters:
--- * pat - Lua pattern that will be matched against the name and description of each spoon in the registered repositories. All text is converted to lowercase before searching it, so you can use all-lowercase in your pattern.
---
--- Returns:
--- * Table containing a list of matching entries. Each entry is a table with the following keys:
--- * name - Spoon name
--- * desc - description of the spoon
--- * repo - identifier in the repository where the match was found
function obj:search(pat)
local res={}
for repo,v in pairs(self.repos) do
if v.data then
for spoon,rec in pairs(v.data) do
if string.find(string.lower(rec.name .. "\n" .. rec.desc), pat) then
table.insert(res, { name = rec.name, desc = rec.desc, repo = repo })
end
end
else
self.logger.ef("Repository data for '%s' not available - call spoon.SpoonInstall:updateRepo('%s'), then try again.", repo, repo)
end
end
return res
end
-- --------------------------------------------------------------------
-- Spoon installation
-- Internal callback function to finalize the installation of a spoon after the zip file has been downloaded.
-- callback, if given, is called with (urlparts, success) as arguments
function obj:_installSpoonFromZipURLgetCallback(urlparts, callback, status, body, headers)
local success=nil
if (status < 100) or (status >= 400) then
self.logger.ef("Error downloading %s. Error code %d: %s", urlparts.absoluteString, status, body or "<none>")
else
-- Write the zip file to disk in a temporary directory
local tmpdir=_x("/usr/bin/mktemp -d", "Error creating temporary directory to download new spoon.")
if tmpdir then
local outfile = string.format("%s/%s", tmpdir, urlparts.lastPathComponent)
local f=assert(io.open(outfile, "w"))
f:write(body)
f:close()
-- Check its contents - only one *.spoon directory should be in there
output = _x(string.format("/usr/bin/unzip -l %s '*.spoon/' | /usr/bin/awk '$NF ~ /\\.spoon\\/$/ { print $NF }' | /usr/bin/wc -l", outfile),
"Error examining downloaded zip file %s, leaving it in place for your examination.", outfile)
if output then
if (tonumber(output) or 0) == 1 then
-- Uncompress the zip file
local outdir = string.format("%s/Spoons", hs.configdir)
if _x(string.format("/usr/bin/unzip -o %s -d %s 2>&1", outfile, outdir),
"Error uncompressing file %s, leaving it in place for your examination.", outfile) then
-- And finally, install it using Hammerspoon itself
self.logger.f("Downloaded and installed %s", urlparts.absoluteString)
_x(string.format("/bin/rm -rf '%s'", tmpdir), "Error removing directory %s", tmpdir)
success=true
end
else
self.logger.ef("The downloaded zip file %s is invalid - it should contain exactly one spoon. Leaving it in place for your examination.", outfile)
end
end
end
end
if callback then
callback(urlparts, success)
end
return success
end
--- SpoonInstall:asyncInstallSpoonFromZipURL(url, callback)
--- Method
--- Asynchronously download a Spoon zip file and install it.
---
--- Parameters:
--- * url - URL of the zip file to install.
--- * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:
--- * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file
--- * success - boolean indicating whether the installation was successful
---
--- Returns:
--- * `true` if the installation was correctly initiated (i.e. the URL is valid), `false` otherwise
function obj:asyncInstallSpoonFromZipURL(url, callback)
local urlparts = hs.http.urlParts(url)
local dlfile = urlparts.lastPathComponent
if dlfile and dlfile ~= "" and urlparts.pathExtension == "zip" then
hs.http.asyncGet(url, nil, hs.fnutils.partial(self._installSpoonFromZipURLgetCallback, self, urlparts, callback))
return true
else
self.logger.ef("Invalid URL %s, must point to a zip file", url)
return nil
end
end
--- SpoonInstall:installSpoonFromZipURL(url)
--- Method
--- Synchronously download a Spoon zip file and install it.
---
--- Parameters:
--- * url - URL of the zip file to install.
---
--- Returns:
--- * `true` if the installation was successful, `nil` otherwise
function obj:installSpoonFromZipURL(url)
local urlparts = hs.http.urlParts(url)
local dlfile = urlparts.lastPathComponent
if dlfile and dlfile ~= "" and urlparts.pathExtension == "zip" then
a,b,c=hs.http.get(url)
return self:_installSpoonFromZipURLgetCallback(urlparts, nil, a, b, c)
else
self.logger.ef("Invalid URL %s, must point to a zip file", url)
return nil
end
end
-- Internal function to check if a Spoon/Repo combination is valid
function obj:_is_valid_spoon(name, repo)
if self.repos[repo] then
if self.repos[repo].data then
if self.repos[repo].data[name] then
return true
else
self.logger.ef("Spoon '%s' does not exist in repository '%s'. Please check and try again.", name, repo)
end
else
self.logger.ef("Repository data for '%s' not available - call spoon.SpoonInstall:updateRepo('%s'), then try again.", repo, repo)
end
else
self.logger.ef("Invalid or unknown repository '%s'", repo)
end
return nil
end
--- SpoonInstall:asyncInstallSpoonFromRepo(name, repo, callback)
--- Method
--- Asynchronously install a Spoon from a registered repository
---
--- Parameters:
--- * name - Name of the Spoon to install.
--- * repo - Name of the repository to use. Defaults to `"default"`
--- * callback - if given, a function to call after the installation finishes (also if it fails). The function receives the following arguments:
--- * urlparts - Result of calling `hs.http.urlParts` on the URL of the Spoon zip file
--- * success - boolean indicating whether the installation was successful
---
--- Returns:
--- * `true` if the installation was correctly initiated (i.e. the repo and spoon name were correct), `false` otherwise.
function obj:asyncInstallSpoonFromRepo(name, repo, callback)
if not repo then repo = 'default' end
if self:_is_valid_spoon(name, repo) then
self:asyncInstallSpoonFromZipURL(self.repos[repo].data[name].download_url, callback)
end
return nil
end
--- SpoonInstall:installSpoonFromRepo(name, repo)
--- Method
--- Synchronously install a Spoon from a registered repository
---
--- Parameters:
--- * name = Name of the Spoon to install.
--- * repo - Name of the repository to use. Defaults to `"default"`
---
--- Returns:
--- * `true` if the installation was successful, `nil` otherwise.
function obj:installSpoonFromRepo(name, repo, callback)
if not repo then repo = 'default' end
if self:_is_valid_spoon(name, repo) then
return self:installSpoonFromZipURL(self.repos[repo].data[name].download_url)
end
return nil
end
--- SpoonInstall:andUse(name, arg)
--- Method
--- Declaratively install, load and configure a Spoon
---
--- Parameters:
--- * name - the name of the Spoon to install (without the `.spoon` extension). If the Spoon is already installed, it will be loaded using `hs.loadSpoon()`. If it is not installed, it will be installed using `SpoonInstall:asyncInstallSpoonFromRepo()` and then loaded.
--- * arg - if provided, can be used to specify the configuration of the Spoon. The following keys are recognized (all are optional):
--- * repo - repository from where the Spoon should be installed if not present in the system, as defined in `SpoonInstall.repos`. Defaults to `"default"`.
--- * config - a table containing variables to be stored in the Spoon object to configure it. For example, `config = { answer = 42 }` will result in `spoon.<LoadedSpoon>.answer` being set to 42.
--- * hotkeys - a table containing hotkey bindings. If provided, will be passed as-is to the Spoon's `bindHotkeys()` method. The special string `"default"` can be given to use the Spoons `defaultHotkeys` variable, if it exists.
--- * fn - a function which will be called with the freshly-loaded Spoon object as its first argument.
--- * loglevel - if the Spoon has a variable called `logger`, its `setLogLevel()` method will be called with this value.
--- * start - if `true`, call the Spoon's `start()` method after configuring everything else.
--- * disable - if `true`, do nothing. Easier than commenting it out when you want to temporarily disable a spoon.
---
--- Returns:
--- * None
function obj:andUse(name, arg)
if not arg then arg = {} end
if arg.disable then return true end
if hs.spoons.use(name, arg, true) then
return true
else
local repo = arg.repo or "default"
if self.repos[repo] then
if self.repos[repo].data then
local load_and_config = function(_, success)
if success then
hs.notify.show("Spoon installed by SpoonInstall", name .. ".spoon is now available", "")
hs.spoons.use(name, arg)
else
obj.logger.ef("Error installing Spoon '%s' from repo '%s'", name, repo)
end
end
if self.use_syncinstall then
return load_and_config(nil, self:installSpoonFromRepo(name, repo))
else
self:asyncInstallSpoonFromRepo(name, repo, load_and_config)
end
else
local update_repo_and_continue = function(_, success)
if success then
obj:andUse(name, arg)
else
obj.logger.ef("Error updating repository '%s'", repo)
end
end
if self.use_syncinstall then
return update_repo_and_continue(nil, self:updateRepo(repo))
else
self:asyncUpdateRepo(repo, update_repo_and_continue)
end
end
else
obj.logger.ef("Unknown repository '%s' for Spoon", repo, name)
end
end
end
return obj

@ -13,28 +13,10 @@
: uielement
: window} hs)
(local {: mash : smash : modal-bind} (require :hotkey))
(local log (logger.new :log :info))
(set logger.defaultLogLevel :info)
(set window.animationDuration 0.0)
(load_spoon :MiroWindowsManager)
;; fnlfmt: skip
(let [{:MiroWindowsManager wm} spoon]
(wm:bindHotkeys {:up [mash :k]
:left [mash :h]
:down [mash :j]
:right [mash :l]
:fullscreen [mash :m]
;; :center [mash "c"]
;; :move [smash "m"]
;; :resize [mash "d"]
})
;; (set wm.fullScreenSizes [1 (/ 4 3) 2]) ; only fullscreen
)
(local {: mash : smash : modal-bind} (require :hotkey))
;; debugging
; (hotkey.bind mash "d" #(dialog.blockAlert "message" "text" "one" "two"))
@ -105,7 +87,21 @@
;;; Spoons
(: (load_spoon :ReloadConfiguration) :start)
(load_spoon :SpoonInstall)
(local {:SpoonInstall Install} spoon)
(set Install.use_syncinstall true)
;; fnlfmt: skip
(let [hotkeys {:up [mash :k]
:left [mash :h]
:down [mash :j]
:right [mash :l]
:fullscreen [mash :m]
:nextscreen [mash :n]}]
(set window.animationDuration 0.0)
(Install:andUse :MiroWindowsManager {: hotkeys}))
(Install:andUse :ReloadConfiguration)
;; Local overrides
(when (fs.attributes :local.fnl)

Loading…
Cancel
Save