Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd support for command extensions #1037
Draft
Conversation
When executing `gh <cmd>`, if `<cmd>` is not a built-in command, this searches `~/.config/gh/gh-commands/*` and in PATH for executables named `gh-<cmd>` and runs the first one found. All arguments are forwarded to the executable and the following environment variables are set: - GITHUB_TOKEN for API calls; - GH_BASEREPO with the `OWNER/REPO` pair determined from git remotes. Additionally, the executable may provide shell completions by respecting the mode in which the 1st argument is `__complete` and by writing completion options as separate lines of output.
If multiple extensions provide a `gh-foo` command, invoking `gh foo`
will result in an error. The user will have to specify the extension
namespace explicitly, e.g.
$ gh @user1/foo
$ gh @user2/foo
|
Some example commands are now in https://github.com/mislav/gh-commands. Installing that repository per its README will grant you the Commands provided there:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


mislav commentedMay 28, 2020
•
edited
When executing
gh <cmd>, if<cmd>is not a built-in command, this searches~/.config/gh/gh-commands/*and in PATH for executables namedgh-<cmd>and runs the first one found.All arguments are forwarded to the executable and the following environment variables are set:
<owner>/<repo>pair determined from git remotes.Example: command to identify the authenticated user
If saved as
gh-whoamisomewhere in the user's PATH, the command is invoked like so:All custom commands are listed in shell completions for the
ghcommand; e.g. typinggh who<Tab>will expand togh whoami.Additionally, the executable may provide its own shell completions by respecting when the 1st argument is
__completeand writing completion options as separate lines of output:TODO:
~/.config/gh/gh-commands/*__completegh __complete <cmd> ''returning extra results