The extensions that were in Toolshed's own repository, a folder each: brreg, dashboard-icons, databricks, docker, github, homebrew, norway, projects, scripts, secrets, wikipedia and yr. Toolshed installs them from here, in Settings → Extensions → From a repository, and the README says how
This commit is contained in:
44 files changed
+7978
-1
No files matched your search
@@ -0,0 +1,674 @@
|
||||
-- Homebrew, as on the command line: "brew install jq" lists what you could install and Enter
|
||||
-- installs it, "brew uninstall jq" what's installed, "brew upgrade" what has an update, "brew
|
||||
-- list" what you installed, "brew services" the services; "brew info jq" finds everything by
|
||||
-- name, saying what's installed and what has an update, and Enter shows a package's details
|
||||
-- there. ⌘K installs, upgrades, uninstalls or pins a package, or opens it on formulae.brew.sh.
|
||||
-- "brew" alone offers the verbs, and a verb half typed ("brew un") those it could become: Enter
|
||||
-- types it ("brew uninstall "), to go on from there. A whole name ("brew jq") is that package.
|
||||
-- "brew upgrade" lists what's outdated, Upgrade all first; "brew update", "brew cleanup" and
|
||||
-- "brew doctor" take nothing more, so choosing them runs them. What changes what's installed
|
||||
-- runs in the background, one at a time, shown in Active while it does and saying when it's
|
||||
-- done, a page showing what Homebrew says as it goes; one that needs a password can be run in
|
||||
-- Terminal instead, where it can ask for it. Its text is in locales/.
|
||||
|
||||
local cache = toolshed.cache_dir()
|
||||
local installed_file = cache .. "/installed.json"
|
||||
-- Asking brew what's installed takes a second, so it's asked in the background when what's
|
||||
-- known is older than this, and searches use what's known meanwhile.
|
||||
local refresh_seconds = 60
|
||||
-- Search finds at most this many, as a launcher list shows no more.
|
||||
local most = 40
|
||||
|
||||
local quoted = toolshed.shell_quote
|
||||
|
||||
local escape = toolshed.escape
|
||||
|
||||
local function trim(s)
|
||||
return (tostring(s or ""):gsub("^%s+", ""):gsub("%s+$", ""))
|
||||
end
|
||||
|
||||
local modified = toolshed.file.modified
|
||||
|
||||
-- brew is found once, by the shell's PATH, so Terminal runs the same one whatever its own PATH.
|
||||
local brew_path
|
||||
local function brew()
|
||||
if not brew_path then brew_path = trim(toolshed.exec({ "sh", "-c", "command -v brew" })) end
|
||||
return brew_path
|
||||
end
|
||||
|
||||
-- quiet runs brew without it updating itself first, which only installing and upgrading need.
|
||||
local function quiet(...)
|
||||
return toolshed.exec({ "env", "HOMEBREW_NO_AUTO_UPDATE=1", brew(), ... })
|
||||
end
|
||||
|
||||
-- installed_command writes what's installed to the file, swapped in whole so a search never
|
||||
-- reads half of it.
|
||||
local function installed_command()
|
||||
return "HOMEBREW_NO_AUTO_UPDATE=1 " .. quoted(brew()) .. " info --json=v2 --installed > " ..
|
||||
quoted(installed_file .. ".tmp") .. " 2>/dev/null && mv " .. quoted(installed_file .. ".tmp") .. " " .. quoted(installed_file)
|
||||
end
|
||||
|
||||
-- refresh_in_background asks brew what's installed, quietly, once at a time.
|
||||
local function refresh_in_background()
|
||||
toolshed.activities.set { key = "refresh", title = toolshed.t("jobs.refresh.title"), description = toolshed.t("jobs.refresh.description"), quiet = true, run = { "sh", "-c", installed_command() }, timeout = 120 }
|
||||
end
|
||||
|
||||
-- in_terminal runs a brew command in Terminal, as a .command file macOS opens without asking
|
||||
-- for permission to control it, then writes down what's installed now: for one that failed in
|
||||
-- the background, as it needs a password, which Terminal can ask for.
|
||||
local function in_terminal(name, args)
|
||||
local words = { quoted(brew()) }
|
||||
for _, a in ipairs(args) do table.insert(words, quoted(a)) end
|
||||
local path = cache .. "/" .. name:gsub("[^%w%-_]", "_") .. ".command"
|
||||
local f = assert(io.open(path, "w"))
|
||||
f:write("#!/bin/sh\nclear\n" .. table.concat(words, " ") .. "\nstatus=$?\n" .. installed_command() .. "\nexit $status\n")
|
||||
f:close()
|
||||
toolshed.exec({ "chmod", "+x", path })
|
||||
toolshed.open(path)
|
||||
end
|
||||
|
||||
-- A brew command runs in the background as an activity, shown while it runs and saying when
|
||||
-- it's done or why it failed, one at a time as Homebrew needs. One that ended less than this
|
||||
-- ago is the one the page is showing; older, running it again starts afresh.
|
||||
local done_seconds = 30
|
||||
|
||||
-- output is the last lines of what brew said, its colours taken out.
|
||||
local function output(text, most_lines)
|
||||
local lines = {}
|
||||
for line in (text or ""):gsub("\27%[[%d;]*%a", ""):gmatch("[^\n]+") do table.insert(lines, line) end
|
||||
return table.concat(lines, "\n", math.max(1, #lines - most_lines + 1))
|
||||
end
|
||||
|
||||
-- brew_page runs a brew command, unless it's under way, and shows how it goes: what brew says
|
||||
-- while it runs, all of it once done, and on a failure, a way to run it in Terminal, where it
|
||||
-- can ask for a password. What's installed is read again afterwards.
|
||||
local function brew_page(name, args)
|
||||
local typed = "brew " .. table.concat(args, " ")
|
||||
local key = "run-" .. name:lower():gsub("[^%w_-]", "-")
|
||||
local now = toolshed.activities.get(key)
|
||||
if not now or (now.ended and os.time() - now.ended >= done_seconds) then
|
||||
local command = { "env", "HOMEBREW_NO_COLOR=1", "HOMEBREW_NO_EMOJI=1", "HOMEBREW_NO_ENV_HINTS=1", brew() }
|
||||
for _, a in ipairs(args) do table.insert(command, a) end
|
||||
now = toolshed.activities.set {
|
||||
key = key, tool = "brew", title = toolshed.t("run.running", { command = typed }), icon = "package",
|
||||
run = command, queue = "brew", timeout = 3600,
|
||||
ending = { done = toolshed.t("run.done", { command = typed }), failed = toolshed.t("run.failed", { command = typed }) },
|
||||
after = { action = "ran" },
|
||||
}
|
||||
end
|
||||
local running = now.state == "waiting" or now.state == "running"
|
||||
local heading = toolshed.t(running and "run.running" or now.state == "done" and "run.done" or "run.failed", { command = typed })
|
||||
local html = '<div class="page"><div class="empty">' .. escape(heading) .. '</div><div class="log" style="margin-top: 12px; white-space: pre-wrap">' ..
|
||||
escape(output(now.output, running and 12 or 400)) .. "</div></div>"
|
||||
if running then return { html = html, refresh = 1 } end
|
||||
if now.state == "done" then return { html = html } end
|
||||
return { html = html, jigs = { {
|
||||
title = toolshed.t("run.in-terminal"), subtitle = typed, icon = "terminal", tool = "terminal", action = "run",
|
||||
data = { name = name, args = args },
|
||||
} } }
|
||||
end
|
||||
|
||||
-- A package as the extension keeps it: what's needed to list it, not all brew says.
|
||||
local function slim(p, kind)
|
||||
if kind == "cask" then
|
||||
return {
|
||||
name = p.token, kind = "cask", desc = p.desc, homepage = p.homepage, latest = p.version,
|
||||
version = p.installed, on_request = true, pinned = false,
|
||||
-- Casks that update themselves aren't upgraded by brew upgrade, so brew doesn't count them.
|
||||
outdated = p.outdated and not p.auto_updates,
|
||||
}
|
||||
end
|
||||
local last = p.installed and p.installed[#p.installed] or {}
|
||||
-- A new build of the same version is a revision, which the installed version names too:
|
||||
-- 9.12_1 after 9.12.
|
||||
local latest = p.versions and p.versions.stable
|
||||
if latest and (p.revision or 0) > 0 then latest = latest .. "_" .. p.revision end
|
||||
return {
|
||||
name = p.name, kind = "formula", desc = p.desc, homepage = p.homepage,
|
||||
latest = latest, version = last.version,
|
||||
on_request = last.installed_on_request, pinned = p.pinned, outdated = p.outdated,
|
||||
}
|
||||
end
|
||||
|
||||
local known, known_at = nil, 0
|
||||
|
||||
-- installed is what's installed, as last written down: the first time it's asked now, and when
|
||||
-- it's older than refresh_seconds it's asked again in the background.
|
||||
local function installed()
|
||||
local at = modified(installed_file)
|
||||
if not at then
|
||||
local out = quiet("info", "--json=v2", "--installed")
|
||||
local f = assert(io.open(installed_file, "w"))
|
||||
f:write(out)
|
||||
f:close()
|
||||
at = modified(installed_file)
|
||||
elseif os.time() - at > refresh_seconds then
|
||||
refresh_in_background()
|
||||
end
|
||||
if known and known_at == at then return known end
|
||||
local f = io.open(installed_file)
|
||||
local data = f and toolshed.json.decode(f:read("*a")) or {}
|
||||
if f then f:close() end
|
||||
local list = {}
|
||||
for _, p in ipairs(data.formulae or {}) do table.insert(list, slim(p, "formula")) end
|
||||
for _, p in ipairs(data.casks or {}) do table.insert(list, slim(p, "cask")) end
|
||||
known, known_at = list, at
|
||||
return list
|
||||
end
|
||||
|
||||
-- Every formula and cask there is, as brew formulae and brew casks list them, written down
|
||||
-- and asked again in the background when older than names_seconds: brew's own files for them
|
||||
-- change as Homebrew does.
|
||||
local names_file = cache .. "/names.txt"
|
||||
local names_seconds = 6 * 3600
|
||||
|
||||
local function names_command()
|
||||
local b = quoted(brew())
|
||||
return "(" .. b .. " formulae 2>/dev/null | sed 's/^/formula /'; " .. b .. " casks 2>/dev/null | sed 's/^/cask /') > " ..
|
||||
quoted(names_file .. ".tmp") .. " && mv " .. quoted(names_file .. ".tmp") .. " " .. quoted(names_file)
|
||||
end
|
||||
|
||||
local names, names_at = nil, 0
|
||||
local function every_name()
|
||||
local at = modified(names_file)
|
||||
if not at then
|
||||
toolshed.exec({ "sh", "-c", "export HOMEBREW_NO_AUTO_UPDATE=1; " .. names_command() })
|
||||
at = modified(names_file)
|
||||
elseif os.time() - at > names_seconds then
|
||||
toolshed.activities.set { key = "names", title = toolshed.t("jobs.names.title"), description = toolshed.t("jobs.names.description"), quiet = true, run = { "sh", "-c", "export HOMEBREW_NO_AUTO_UPDATE=1; " .. names_command() }, timeout = 300 }
|
||||
end
|
||||
if names and names_at == at then return names end
|
||||
names = {}
|
||||
local f = io.open(names_file)
|
||||
if f then
|
||||
for line in f:lines() do
|
||||
local kind, name = line:match("^(%a+) (.+)$")
|
||||
if name then table.insert(names, { name = name, kind = kind }) end
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
names_at = at
|
||||
return names
|
||||
end
|
||||
|
||||
local function key(name, kind) return kind .. ":" .. name end
|
||||
|
||||
-- jig is a package as a row: its state and what it's for, and the actions that fit it.
|
||||
-- Its tags say at a glance whether it's installed, has an update or is pinned; the subtitle
|
||||
-- says which version, and what it's for.
|
||||
local function jig(p)
|
||||
local state, tags = toolshed.t(p.kind == "cask" and "kind.cask" or "kind.formula"), {}
|
||||
if p.version then
|
||||
table.insert(tags, { text = toolshed.t("tag.installed"), tint = "green", icon = "circle-check" })
|
||||
if p.pinned then
|
||||
table.insert(tags, { text = toolshed.t("tag.pinned"), tint = "gray", icon = "pin" })
|
||||
elseif p.outdated then
|
||||
table.insert(tags, { text = toolshed.t("tag.update"), tint = "orange", icon = "circle-arrow-up" })
|
||||
end
|
||||
state = p.outdated and (p.version .. " → " .. (p.latest or "?")) or p.version
|
||||
end
|
||||
local actions = { "info" }
|
||||
if p.version then
|
||||
if p.outdated and not p.pinned then table.insert(actions, "upgrade") end
|
||||
table.insert(actions, "uninstall")
|
||||
if p.kind == "formula" then table.insert(actions, p.pinned and "unpin" or "pin") end
|
||||
else
|
||||
table.insert(actions, "install")
|
||||
end
|
||||
table.insert(actions, "open-site")
|
||||
table.insert(actions, "copy-name")
|
||||
return {
|
||||
title = p.name, subtitle = state .. ((p.desc and p.desc ~= "") and (" · " .. p.desc) or ""), tags = tags,
|
||||
icon = p.kind == "cask" and "app-window" or "package", tool = "search", actions = actions,
|
||||
data = { name = p.name, kind = p.kind },
|
||||
}
|
||||
end
|
||||
|
||||
-- mine is what's installed that keep allows, updates first.
|
||||
local function mine(keep)
|
||||
local list = {}
|
||||
for _, p in ipairs(installed()) do
|
||||
if keep(p) then table.insert(list, p) end
|
||||
end
|
||||
table.sort(list, function(a, b)
|
||||
if (a.outdated or false) ~= (b.outdated or false) then return a.outdated end
|
||||
return a.name < b.name
|
||||
end)
|
||||
return list
|
||||
end
|
||||
|
||||
-- find is the packages whose name has what's typed, those keep allows: the name itself first,
|
||||
-- then those starting with it, then the rest; within each, what's installed first, then the
|
||||
-- shortest. Only what's installed is looked through when that's all keep allows.
|
||||
local function find(typed, keep, installed_only)
|
||||
local q = typed:lower()
|
||||
local have = {}
|
||||
for _, p in ipairs(installed()) do have[key(p.name, p.kind)] = p end
|
||||
local found = {}
|
||||
local function consider(name, kind)
|
||||
local at = name:lower():find(q, 1, true)
|
||||
if not at then return end
|
||||
local k = key(name, kind)
|
||||
local p = have[k] or { name = name, kind = kind }
|
||||
if found[k] or not keep(p) then return end
|
||||
found[k] = { p = p, rank = (name:lower() == q and 0) or (at == 1 and 1) or 2 }
|
||||
end
|
||||
for _, p in ipairs(installed()) do consider(p.name, p.kind) end
|
||||
if not installed_only then
|
||||
for _, n in ipairs(every_name()) do consider(n.name, n.kind) end
|
||||
end
|
||||
local list = {}
|
||||
for _, f in pairs(found) do table.insert(list, f) end
|
||||
table.sort(list, function(a, b)
|
||||
if a.rank ~= b.rank then return a.rank < b.rank end
|
||||
if (a.p.version ~= nil) ~= (b.p.version ~= nil) then return a.p.version ~= nil end
|
||||
if #a.p.name ~= #b.p.name then return #a.p.name < #b.p.name end
|
||||
return a.p.name < b.p.name
|
||||
end)
|
||||
local out = {}
|
||||
for i = 1, math.min(#list, most) do table.insert(out, list[i].p) end
|
||||
return out
|
||||
end
|
||||
|
||||
local function page(body) return '<div class="page">' .. body .. "</div>" end
|
||||
local function tile(icon) return '<span class="tile small" data-icon="' .. icon .. '"></span>' end
|
||||
|
||||
local function card(title, icon, tint, facts, wide)
|
||||
local rows = {}
|
||||
for _, f in ipairs(facts) do
|
||||
if f[2] and f[2] ~= "" then table.insert(rows, "<dt>" .. escape(toolshed.t(f[1])) .. "</dt><dd>" .. f[2] .. "</dd>") end
|
||||
end
|
||||
if #rows == 0 then return "" end
|
||||
return '<div class="card' .. (wide and " wide" or "") .. '" data-tint="' .. tint .. '"><div class="card-head">' .. tile(icon) ..
|
||||
escape(toolshed.t(title)) .. '</div><dl class="kv">' .. table.concat(rows) .. "</dl></div>"
|
||||
end
|
||||
|
||||
local function site(data)
|
||||
return "https://formulae.brew.sh/" .. data.kind .. "/" .. data.name
|
||||
end
|
||||
|
||||
-- details is a package's page, from what brew says about it now.
|
||||
local function details(data)
|
||||
local info = toolshed.json.decode(quiet("info", "--json=v2", data.kind == "cask" and "--cask" or "--formula", data.name))
|
||||
local raw = (data.kind == "cask" and info.casks or info.formulae)[1]
|
||||
if not raw then error(toolshed.t("not-found", { name = data.name })) end
|
||||
local p = slim(raw, data.kind)
|
||||
local status
|
||||
if not p.version then
|
||||
status = toolshed.t("status.not-installed")
|
||||
elseif p.outdated then
|
||||
status = '<span class="dot"></span>' .. escape(toolshed.t("status.update", { latest = p.latest or "?" }))
|
||||
else
|
||||
status = '<span class="dot on"></span>' .. escape(toolshed.t(p.pinned and "status.pinned" or "status.current"))
|
||||
end
|
||||
local link = p.homepage and ('<span class="ellipsis">' .. escape(p.homepage) .. "</span>")
|
||||
local cards = {
|
||||
card("card.package", data.kind == "cask" and "app-window" or "package", "yellow", {
|
||||
{ "fact.description", escape(p.desc) },
|
||||
{ "fact.kind", escape(toolshed.t(data.kind == "cask" and "kind.cask" or "kind.formula")) },
|
||||
{ "fact.tap", escape(raw.tap) },
|
||||
{ "fact.license", escape(raw.license) },
|
||||
{ "fact.homepage", link },
|
||||
}),
|
||||
card("card.version", "download", "green", {
|
||||
{ "fact.latest", escape(p.latest) },
|
||||
{ "fact.installed", escape(p.version or toolshed.t("none")) },
|
||||
{ "fact.status", status },
|
||||
}),
|
||||
}
|
||||
local deps = raw.dependencies
|
||||
if data.kind == "formula" and deps and #deps > 0 then
|
||||
table.insert(cards, card("card.dependencies", "boxes", "teal", { { "fact.needs", escape(table.concat(deps, ", ")) } }, true))
|
||||
end
|
||||
local caveats = raw.caveats and raw.caveats ~= "" and
|
||||
('<div class="note">' .. escape(toolshed.t("caveats")) .. '</div><div class="log">' .. escape(raw.caveats) .. "</div>") or ""
|
||||
return page('<div class="cards">' .. table.concat(cards) .. "</div>" .. caveats)
|
||||
end
|
||||
|
||||
-- updates is what's outdated as a page: how many, and a line each, to upgrade.
|
||||
|
||||
-- services are brew's background services, as rows to start, stop or restart.
|
||||
local function services()
|
||||
local list = toolshed.json.decode(quiet("services", "list", "--json")) or {}
|
||||
local jigs = {}
|
||||
for _, s in ipairs(list) do
|
||||
local running = s.status == "started" or s.status == "scheduled"
|
||||
table.insert(jigs, {
|
||||
title = s.name, subtitle = toolshed.t("service." .. (s.status or "none")), tool = "service",
|
||||
icon = running and "play" or "circle-stop", actions = running and { "stop", "restart" } or { "start" },
|
||||
data = { name = s.name },
|
||||
})
|
||||
end
|
||||
if #jigs == 0 then error(toolshed.t("no-services")) end
|
||||
return { jigs = jigs }
|
||||
end
|
||||
|
||||
-- A tap's name is user/repo; on GitHub it's github.com/user/homebrew-repo, unless an address
|
||||
-- is given for it.
|
||||
local function tap_page(name)
|
||||
local user, repo = name:match("^([^/]+)/(.+)$")
|
||||
return "https://github.com/" .. user .. "/homebrew-" .. repo
|
||||
end
|
||||
|
||||
-- Asking brew about its taps takes a second, so what it says is kept for a minute, and
|
||||
-- forgotten when a tap is added, removed or trusted.
|
||||
local tap_info, tap_info_at = nil, 0
|
||||
local function forget_taps() tap_info = nil end
|
||||
|
||||
-- installed_taps are the third-party taps brew has: Homebrew's own aren't listed, as brew tap
|
||||
-- doesn't list them.
|
||||
local function installed_taps()
|
||||
if not tap_info or os.time() - tap_info_at > 60 then
|
||||
tap_info, tap_info_at = {}, os.time()
|
||||
for _, t in ipairs(toolshed.json.decode(quiet("tap-info", "--json", "--installed")) or {}) do
|
||||
if not t.official then table.insert(tap_info, t) end
|
||||
end
|
||||
end
|
||||
return tap_info
|
||||
end
|
||||
|
||||
-- tap_status says what a tap holds and when it last changed; whether Homebrew trusts it, as it
|
||||
-- loads nothing from one it doesn't, is its tag.
|
||||
local function tap_status(t)
|
||||
local parts = {}
|
||||
local formulae, casks = #(t.formula_names or {}), #(t.cask_tokens or {})
|
||||
if formulae > 0 then table.insert(parts, toolshed.t("tap.formulae", { count = formulae })) end
|
||||
if casks > 0 then table.insert(parts, toolshed.t("tap.casks", { count = casks })) end
|
||||
if t.private then table.insert(parts, toolshed.t("tap.private")) end
|
||||
if t.last_commit then table.insert(parts, toolshed.t("tap.updated", { when = t.last_commit })) end
|
||||
return table.concat(parts, " · ")
|
||||
end
|
||||
|
||||
-- taps are the third-party repositories brew has, those whose name has what's typed, with how
|
||||
-- each is; and when what's typed is a tap brew doesn't have yet ("user/repo", maybe with an
|
||||
-- address after it), a row first to add it.
|
||||
local function taps(typed)
|
||||
local name, address = typed:match("^(%S+)%s*(.-)$")
|
||||
local q = (name or ""):lower()
|
||||
local jigs, have = {}, false
|
||||
for _, t in ipairs(installed_taps()) do
|
||||
if t.name:lower() == q then have = true end
|
||||
if q == "" or t.name:lower():find(q, 1, true) then
|
||||
table.insert(jigs, {
|
||||
title = t.name, subtitle = tap_status(t), icon = "git-branch", tool = "tap",
|
||||
tags = { t.trusted and { text = toolshed.t("tap.trusted"), tint = "green", icon = "shield-check" }
|
||||
or { text = toolshed.t("tap.untrusted"), tint = "orange", icon = "shield-check" } },
|
||||
actions = { "open-tap", t.trusted and "untrust" or "trust", "untap" },
|
||||
data = { name = t.name, page = t.remote or tap_page(t.name) },
|
||||
})
|
||||
end
|
||||
end
|
||||
if name and not have and name:match("^[%w_.-]+/[%w_.-]+$") then
|
||||
table.insert(jigs, 1, {
|
||||
title = toolshed.t("tap.add", { name = name }),
|
||||
subtitle = address ~= "" and address or tap_page(name):gsub("^https://", ""),
|
||||
icon = "download", tool = "tap", action = "tap", actions = { "tap" }, data = { name = name, address = address },
|
||||
})
|
||||
end
|
||||
return jigs
|
||||
end
|
||||
|
||||
-- run_row runs a brew command that takes nothing more, like doctor, showing how it goes.
|
||||
local function run_row(key, title, subtitle, icon, args)
|
||||
return { key = key, title = title, subtitle = subtitle, icon = icon, tool = "brew", action = "run", data = { name = key, args = args } }
|
||||
end
|
||||
|
||||
local function any() return true end
|
||||
local function absent(p) return p.version == nil end
|
||||
local function present(p) return p.version ~= nil end
|
||||
local function updatable(p) return p.version ~= nil and p.outdated and not p.pinned end
|
||||
local function yours(p) return p.on_request end
|
||||
|
||||
-- verbs are what can follow brew, as on the command line, in the order they're offered: each
|
||||
-- lists what it fits, and Enter does it. installed means only what's installed can fit; all is
|
||||
-- what it lists with nothing more typed: for uninstall what you installed, not what came along
|
||||
-- with it. acts_on is what Enter does it to, when it lists more: install shows what's installed
|
||||
-- too, saying so, and Enter shows its details. services and tap list what they're about instead.
|
||||
local order = { "install", "uninstall", "upgrade", "list", "info", "services", "tap", "update", "cleanup", "doctor" }
|
||||
local verbs = {
|
||||
install = { icon = "download", keep = any, action = "install", acts_on = absent },
|
||||
uninstall = { icon = "trash-2", keep = present, action = "uninstall", installed = true, all = yours },
|
||||
upgrade = { icon = "circle-arrow-up", keep = updatable, action = "upgrade", installed = true, all = updatable },
|
||||
list = { icon = "package", keep = yours, installed = true, all = yours },
|
||||
info = { icon = "info", keep = any },
|
||||
services = { icon = "server", rows = function()
|
||||
local ok, found = pcall(services)
|
||||
return ok and found.jigs or {}
|
||||
end },
|
||||
tap = { icon = "git-branch", rows = taps },
|
||||
-- These take nothing more, so choosing them runs them.
|
||||
update = { icon = "refresh-cw", runs = { "update" } },
|
||||
cleanup = { icon = "sparkles", runs = { "cleanup" } },
|
||||
doctor = { icon = "stethoscope", runs = { "doctor" } },
|
||||
}
|
||||
-- The other names brew knows them by.
|
||||
local aliases = { remove = "uninstall", rm = "uninstall", ls = "list", taps = "tap", outdated = "upgrade", updates = "upgrade" }
|
||||
|
||||
-- verb_rows are the verbs what's typed could become ("un" → uninstall), all of them for
|
||||
-- nothing: a row each, saying what it does, that types it after brew, to go on from there.
|
||||
local function verb_rows(word)
|
||||
local rows = {}
|
||||
for _, name in ipairs(order) do
|
||||
local fits = name:sub(1, #word) == word
|
||||
for alias, of in pairs(aliases) do
|
||||
if of == name and alias:sub(1, #word) == word then fits = true end
|
||||
end
|
||||
if fits then
|
||||
local title, about, v = toolshed.t("verb." .. name .. ".title"), toolshed.t("verb." .. name .. ".description"), verbs[name]
|
||||
if v.runs then
|
||||
table.insert(rows, run_row(name, title, about, v.icon, v.runs))
|
||||
else
|
||||
table.insert(rows, { title = title, subtitle = about, icon = v.icon, prefix = name .. " ", actions = {} })
|
||||
end
|
||||
end
|
||||
end
|
||||
return rows
|
||||
end
|
||||
|
||||
-- listed is what's typed after brew: a verb, then what to look for. While a verb is typed,
|
||||
-- the verbs it could become are offered, and a package of exactly that name after them ("brew
|
||||
-- jq"); brew on its own offers every verb.
|
||||
local function listed(rest)
|
||||
local word, typed = rest:match("^(%S+)%s*(.-)%s*$")
|
||||
if not word then return verb_rows("") end
|
||||
word = word:lower()
|
||||
local v = verbs[aliases[word] or word]
|
||||
if not v then
|
||||
if typed ~= "" then return {} end
|
||||
local rows = verb_rows(word)
|
||||
for _, p in ipairs(find(word, function(p) return p.name:lower() == word end)) do table.insert(rows, jig(p)) end
|
||||
return rows
|
||||
end
|
||||
if v.rows then return v.rows(typed) end
|
||||
if v.runs then
|
||||
local name = aliases[word] or word
|
||||
return { run_row(name, toolshed.t("verb." .. name .. ".title"), toolshed.t("verb." .. name .. ".description"), v.icon, v.runs) }
|
||||
end
|
||||
local list
|
||||
if typed ~= "" then
|
||||
list = find(typed, v.keep, v.installed)
|
||||
elseif v.all then
|
||||
list = mine(v.all)
|
||||
else
|
||||
return {}
|
||||
end
|
||||
local jigs = {}
|
||||
if v == verbs.upgrade and typed == "" and #list > 0 then
|
||||
table.insert(jigs, run_row("upgrade-all", toolshed.t("action.upgrade-all"), toolshed.t("upgrade-all.about", { count = #list }),
|
||||
"circle-arrow-up", { "upgrade" }))
|
||||
end
|
||||
for _, p in ipairs(list) do
|
||||
local row = jig(p)
|
||||
if not v.acts_on or v.acts_on(p) then row.action = v.action end
|
||||
table.insert(jigs, row)
|
||||
end
|
||||
return jigs
|
||||
end
|
||||
|
||||
return toolshed.toolbox {
|
||||
key = "homebrew",
|
||||
title = "Homebrew",
|
||||
description = "i18n:toolbox.description",
|
||||
icon = "beer",
|
||||
tint = "yellow",
|
||||
requires = { { command = "brew" } },
|
||||
|
||||
tools = {
|
||||
{
|
||||
key = "search",
|
||||
title = "i18n:tool.search.title",
|
||||
description = "i18n:tool.search.description",
|
||||
words = { "brew", "homebrew" },
|
||||
examples = { "brew install jq", "brew upgrade", "brew uninstall jq", "brew list", "brew services", "brew info jq" },
|
||||
keywords = { "homebrew", "install", "package", "formula", "cask", "installer", "pakke", "outdated", "doctor", "cleanup" },
|
||||
items = true,
|
||||
|
||||
search = function(rest) return listed(rest) end,
|
||||
|
||||
actions = {
|
||||
{
|
||||
key = "info", title = "i18n:action.info", icon = "info",
|
||||
run = function(ctx) return { html = details(ctx.data) } end,
|
||||
},
|
||||
{
|
||||
key = "install", title = "i18n:action.install", icon = "download", shortcut = "cmd+enter",
|
||||
run = function(ctx)
|
||||
return brew_page("install-" .. ctx.data.name, { "install", "--" .. ctx.data.kind, ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "upgrade", title = "i18n:action.upgrade", icon = "circle-arrow-up",
|
||||
run = function(ctx)
|
||||
return brew_page("upgrade-" .. ctx.data.name, { "upgrade", "--" .. ctx.data.kind, ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "uninstall", title = "i18n:action.uninstall", icon = "trash-2", confirm = "i18n:confirm.uninstall",
|
||||
never_default = true,
|
||||
run = function(ctx)
|
||||
return brew_page("uninstall-" .. ctx.data.name, { "uninstall", "--" .. ctx.data.kind, ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "pin", title = "i18n:action.pin", icon = "pin", never_default = true,
|
||||
run = function(ctx)
|
||||
quiet("pin", ctx.data.name)
|
||||
refresh_in_background()
|
||||
return toolshed.t("pinned", { name = ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "unpin", title = "i18n:action.unpin", icon = "pin-off", never_default = true,
|
||||
run = function(ctx)
|
||||
quiet("unpin", ctx.data.name)
|
||||
refresh_in_background()
|
||||
return toolshed.t("unpinned", { name = ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "open-site", title = "i18n:action.open-site", icon = "external-link",
|
||||
run = function(ctx) toolshed.open(site(ctx.data)) end,
|
||||
},
|
||||
{
|
||||
key = "copy-name", title = "i18n:action.copy-name", icon = "copy", shortcut = "cmd+shift+c",
|
||||
run = function(ctx)
|
||||
toolshed.clipboard.copy(ctx.data.name)
|
||||
return toolshed.t("name-copied")
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "tap",
|
||||
title = "i18n:tool.tap.title",
|
||||
hidden = true,
|
||||
items = true,
|
||||
actions = {
|
||||
{
|
||||
key = "open-tap", title = "i18n:action.open-tap", icon = "external-link",
|
||||
run = function(ctx) toolshed.open(ctx.data.page) end,
|
||||
},
|
||||
{
|
||||
key = "tap", title = "i18n:action.tap", icon = "download",
|
||||
run = function(ctx)
|
||||
local args = { "tap", ctx.data.name }
|
||||
if ctx.data.address and ctx.data.address ~= "" then table.insert(args, ctx.data.address) end
|
||||
forget_taps()
|
||||
return brew_page("tap-" .. ctx.data.name, args)
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "trust", title = "i18n:action.trust", icon = "shield-check",
|
||||
run = function(ctx)
|
||||
quiet("trust", "--tap", ctx.data.name)
|
||||
forget_taps()
|
||||
return toolshed.t("trusted", { name = ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "untrust", title = "i18n:action.untrust", icon = "shield-check", never_default = true,
|
||||
run = function(ctx)
|
||||
quiet("untrust", "--tap", ctx.data.name)
|
||||
forget_taps()
|
||||
return toolshed.t("untrusted", { name = ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "untap", title = "i18n:action.untap", icon = "trash-2", confirm = "i18n:confirm.untap", never_default = true,
|
||||
run = function(ctx)
|
||||
forget_taps()
|
||||
return brew_page("untap-" .. ctx.data.name, { "untap", ctx.data.name })
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "service",
|
||||
title = "i18n:tool.service.title",
|
||||
hidden = true,
|
||||
items = true,
|
||||
actions = {
|
||||
{
|
||||
key = "start", title = "i18n:action.start", icon = "play",
|
||||
run = function(ctx)
|
||||
quiet("services", "start", ctx.data.name)
|
||||
return toolshed.t("started", { name = ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "stop", title = "i18n:action.stop", icon = "circle-stop",
|
||||
run = function(ctx)
|
||||
quiet("services", "stop", ctx.data.name)
|
||||
return toolshed.t("stopped", { name = ctx.data.name })
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "restart", title = "i18n:action.restart", icon = "rotate-cw",
|
||||
run = function(ctx)
|
||||
quiet("services", "restart", ctx.data.name)
|
||||
return toolshed.t("restarted", { name = ctx.data.name })
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
-- What a verb that takes nothing more runs, like doctor.
|
||||
key = "brew", title = "i18n:tool.brew.title", hidden = true,
|
||||
actions = { {
|
||||
key = "run", title = "i18n:tool.brew.title", icon = "terminal",
|
||||
run = function(ctx) return brew_page(ctx.data.name, ctx.data.args) end,
|
||||
}, {
|
||||
-- Run as a brew command ends: what's installed is asked again.
|
||||
key = "ran", title = "i18n:tool.brew.title", run = function() refresh_in_background() end,
|
||||
} },
|
||||
},
|
||||
{
|
||||
-- Reached from a command that failed in the background: runs it in Terminal instead.
|
||||
key = "terminal", title = "i18n:run.in-terminal", hidden = true,
|
||||
actions = { {
|
||||
key = "run", title = "i18n:run.in-terminal", icon = "terminal",
|
||||
run = function(ctx) in_terminal(ctx.data.name, ctx.data.args) end,
|
||||
} },
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user