This Alfred 4 workflow provides easy access to GitHub repositories, issue search, local project directories, and more using a configurable shorthand.
This repository contains the Alfred workflow. In addition, you'll need the gh-shorthand
command-line tool and optional RPC server.
- Install the
gh-shorthand
CLI tool. See its README for instructions. - Clone this repository and run
./install.sh
to symlink it into your Alfred workflow directory. - Edit the config vars for this workflow by clicking the
[x]
in the Alfred toolbar:- Change
GH_SHORTHAND
to the path to yourgh-shorthand
binary, either as downloaded from a release or as built from source. This defaults to~/go/bin/gh-shorthand
.
- Change
The Alfred terminal integration is required for the "open in terminal" action. The Alfred integration defaults to Terminal.app, and you can find iTerm configurations at vitorgalvao/custom-iterm-scripts-for-alfred.
The remainder of the configuration lives in ~/.gh-shorthand.yml
. The full configuration file documentation is in the gh-shorthand
repository here.
See the gh-shorthand
completion documentation for the full grammar of these queries.
Given the configuration in ~/.gh-shorthand.yml
:
default_repo: "zerowidth/gh-shorthand"
repos:
df: "zerowidth/dotfiles"
users:
z: "zerowidth"
g [user|user/repo] [issue number|/path]
: open a GitHub repository, a specific issue, and paths within repositories.g foo/bar
opens thefoo/bar
repositoryg z/foo
opens thezerowidth/foo
repository, expanding thez
user shorthand tozerowidth
g df
opens thezerowidth/dotfiles
repository, expanding thedf
repo shorthand.g
(trailing space!) opens the default repository,zerowidth/gh-shorthand
g foo/bar#123
org foo/bar 123
opens issue 123 in thefoo/bar
repositoryg z/foo 123
opens issue 123 in thezerowidth/foo
repository, expanding thez
user shorthandg df 123
opens issue 123 in thezerowidth/dotfiles
repository, expanding thedf
repository shorthandg 123
opens issue (or pull request) #123 in the default repositoryg foo/bar /branches
opens the default repository with the/branches
path appendedg z/foo /branches
opens thezerowidth/foo/branches
pathg df /branches
openszerowidth/dotfiles/branches
g /branches
opens the default repository/branches
gi [user|user/repo] [query]
: list, search, and open issues/PRs in a repository.gi foo/bar
lists the issues in thefoo/bar
repository.gi foo/bar fixes
searches the issues infoo/bar
for "fixes".gi
(trailing space!) lists the issues in the default repositorygi fixes
searches the default repository's issues for "fixes"- The same shorthand expansion applies:
z/foo
becomeszerowidth/foo
,df
becomeszerowidth/dotfiles
. - Issue search allows the full search syntax , e.g.
gi is:open is:pr
for showing open pull requests in the default repository.
gn [query] [title]
opens the "new issue" page with the provided title in the given repository.gn
(trailing space!) opens the new issue page in the default repositorygn fix a bug
opens the new issue page in the default repository with "fix a bug" as the issue titlegn foo/bar
opens the new issue page in thefoo/bar
repository- User/repository shorthand expansion applies
gp [user|repo] [project number]
lists or shows a specific project in the given or default repository. This does not currently support project title searches.
Given the configuration in ~/.gh-shorthand.yml
:
project_dirs:
~/code
~/work/projects
And the following directory tree:
~
├── code
│ ├── dotfiles
│ └── demo
└── work
└── projects
├── client
└── server
ge df
opens thedotfiles
project with the configured editor.gt df
opens the terminal in thedotfiles
directory.ge wpc
opens the editor withwork/projects/client
.gt wpc
opens the terminal inwork/projects/client
.
Both the gt
and ge
commands have single character aliases: t
and e
respectively.
gir
retrieves a GitHub URL from the clipboard, converts it to an issue reference (as used in GitHub issues), and pastes it into an active editor:https://github.com/github/linguist/issues/1
on the clipboard becomesgithub/linguist#1
- The
gml
command retrieves a GitHub URL from the clipboard and converts it to a markdown link:https://github.com/github/linguist/issues/1
on the clipboard becomes[github/linguist#1](https://github.com/github/linguist/issues/1)
- The
gmd
command uses the RPC server backend to retrieve the issue title for the linked issue and includes it in the generated markdown link:https://github.com/github/linguist/issues/1
becomes[github/linguist#1: Binary detection issues on extensionless files](https://github.com/github/linguist/issues/1)
gml
and gmd
understand fully qualified issue references in the clipboard: github/linguist#1
can be converted to a markdown link without having to look up its URL first. Similarly, gir
can parse the URL out of a markdown link if that's on the clipboard.
Alongside the gir
, gml
, and gmd
commands, this workflow supports inline snippet expansion for the same behavior with even more convenience:
//gir
and//ir
insert an issue reference//gml
and//ml
insert a markdown link//md
and//md
insert a markdown link with description when RPC is enabled
gc
opens an editor for~/.gh-shorthand.yml
to make it easy to adjust the configuration. See thegh-shorthand
configuration docs for more information.
Most repository/issue Alfred results include alternate actions:
cmd-c
to copy the url to the result- hold
cmd
to insert a markdown link - hold
opt
to insert an issue reference - hold
ctrl
to insert a markdown link including an issue description (applies when RPC is enabled)
Whenever a repository, issue, or pull request is displayed in Alfred results, and when the RPC server is enabled, the workflow retrieves and displays the repository description, issue title, and issue/PR state (open, closed, merged). When listing or searching issues in a repository, the RPC server executes that query and display results inline in Alfred. If RPC is disabled, only links to repositories, issues and search pages are displayed.
RPC queries are triggered after a slight delay to prevent unnecessary queries against the API.
Open an issue. The Alfred bits aren't easily shareable or modifiable like most source code is, unfortunately, so PRs might not get merged. I'm happy to consider ideas and requests, though. For anything particularly customized, you might have a better time modifying the workflow in place.