Just Recipes
Autocomplete `just` with the justfile's recipes and aliases, each with its doc comment and parameters.
Double-click the .ottyaddon to install it in Otty (Labs › Addons must be on).
What it can do
completionAdds suggestions to autocomplete for the commands it names.execRuns programs on your computer as you — the commands it uses are in its source below.
Settings
Shown under the addon in Settings › Labs once it’s on.
| Setting | Type | Default | Details |
|---|---|---|---|
just commandjust |
Text | just |
The just binary to run. A full path when it isn't on Otty's PATH. |
Offer private recipesprivate |
Switch | Off | Recipes whose names start with _ or that are marked [private]. |
Install and turn it on
- Turn on Feature Preview in Settings › Advanced, or add
feature-preview = trueto yourconfig.toml. - Open Settings › Labs and switch Addons on.
- Click Install next to Just Recipes under Browse, or download it above and double-click the
.ottyaddon. Otty shows what it asks to do before it installs. - Switch Just Recipes on. Its settings show up right under it.
Source
The whole addon is this script and its addon.toml.
-- Just Recipes: `just <Tab>` offers the recipes and aliases of the justfile
-- `just` would use in the pane's folder, read from `just --dump --dump-format
-- json`. An answer is reused for 10 seconds per folder, so typing a recipe's
-- name runs `just` once.
type Parameter = { name: string, default: any?, kind: string }
type Recipe = { name: string, doc: string?, private: boolean?, parameters: { Parameter }? }
local function signature(recipe: Recipe): string?
local parts = {}
for _, p in recipe.parameters or {} do
local name = p.name
if p.kind == "plus" then
name = "+" .. name
elseif p.kind == "star" then
name = "*" .. name
end
if p.default ~= nil then
name ..= "=" .. tostring(p.default)
end
table.insert(parts, name)
end
return if #parts > 0 then table.concat(parts, " ") else nil
end
local function describe(recipe: Recipe): string?
local sig = signature(recipe)
if recipe.doc and sig then
return recipe.doc .. " · " .. sig
end
return recipe.doc or sig
end
otty.completion.register({
commands = { "just" },
cache = { ttl = 10 },
run = function(ctx)
-- Options are the spec's job; `just --justfile x` points elsewhere.
if string.sub(ctx.partial, 1, 1) == "-" then
return {}
end
for _, token in ctx.tokens do
if token == "-f" or token == "--justfile" or token == "-d" or token == "--working-directory" then
return {}
end
end
local run = otty.exec({ otty.setting("just"), "--dump", "--dump-format", "json" }, { cwd = ctx.cwd, timeout = 3 })
if run.code ~= 0 then
return {}
end
local dump = otty.json.decode(run.stdout)
local items = {}
local private = otty.setting("private")
for name, recipe: Recipe in dump.recipes or {} do
if private or not (recipe.private or string.sub(name, 1, 1) == "_") then
table.insert(items, { text = name, description = describe(recipe) })
end
end
for name, alias in dump.aliases or {} do
table.insert(items, { text = name, description = "alias for " .. alias.target })
end
table.sort(items, function(a, b)
return a.text < b.text
end)
return items
end,
})