GitHub CLI
Autocomplete pull request and issue numbers for `gh pr` and `gh issue` with their titles, from the repository in the pane's folder.
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 |
|---|---|---|---|
gh commandgh |
Text | gh |
The GitHub CLI to run. A full path when it isn't on Otty's PATH. |
How many to listlimit |
Number | 50 |
From 1 to 500. |
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 GitHub CLI under Browse, or download it above and double-click the
.ottyaddon. Otty shows what it asks to do before it installs. - Switch GitHub CLI on. Its settings show up right under it.
Source
The whole addon is this script and its addon.toml.
-- GitHub CLI: `gh pr checkout <Tab>` offers the repository's open pull
-- requests, `gh issue view <Tab>` its open issues — number, title and author.
-- `gh` goes to the network, so an answer is reused for a minute per folder.
-- Subcommands that take one pull request / issue number.
local PR = { checkout = true, view = true, diff = true, merge = true, close = true, reopen = true,
review = true, ready = true, edit = true, comment = true, checks = true }
local ISSUE = { view = true, close = true, reopen = true, edit = true, comment = true,
pin = true, unpin = true, lock = true, unlock = true, transfer = true, delete = true, develop = true }
-- The words before the one being typed, options left out:
-- `gh pr checkout -f 12` → { "gh", "pr", "checkout" }.
local function words(ctx): { string }
local out = {}
local last = if ctx.partial == "" then #ctx.tokens else #ctx.tokens - 1
for i = 1, last do
local t = ctx.tokens[i]
if string.sub(t, 1, 1) ~= "-" then
table.insert(out, t)
end
end
return out
end
local function list(kind: string, cwd: string?)
local args = { otty.setting("gh"), kind, "list", "--state", "open", "--limit", tostring(otty.setting("limit")),
"--json", "number,title,author" }
local run = otty.exec(args, { cwd = cwd, timeout = 8 })
if run.code ~= 0 then
return {}
end
local items = {}
for _, row in otty.json.decode(run.stdout) do
local by = if row.author and row.author.login then " · @" .. row.author.login else ""
table.insert(items, { text = tostring(row.number), description = row.title .. by })
end
return items
end
otty.completion.register({
commands = { "gh" },
cache = { ttl = 60 },
run = function(ctx)
local w = words(ctx)
if #w ~= 3 then
return {}
end
if w[2] == "pr" and PR[w[3]] then
return list("pr", ctx.cwd)
elseif w[2] == "issue" and ISSUE[w[3]] then
return list("issue", ctx.cwd)
end
return {}
end,
})