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-shorthandCLI tool. See its README for instructions. - Clone this repository and run
./install.shto symlink it into your Alfred workflow directory. - Edit the config vars for this workflow by clicking the
[x]in the Alfred toolbar:- Change
GH_SHORTHANDto the path to yourgh-shorthandbinary, 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/baropens thefoo/barrepositoryg z/fooopens thezerowidth/foorepository, expanding thezuser shorthand tozerowidthg dfopens thezerowidth/dotfilesrepository, expanding thedfrepo shorthand.g(trailing space!) opens the default repository,zerowidth/gh-shorthandg foo/bar#123org foo/bar 123opens issue 123 in thefoo/barrepositoryg z/foo 123opens issue 123 in thezerowidth/foorepository, expanding thezuser shorthandg df 123opens issue 123 in thezerowidth/dotfilesrepository, expanding thedfrepository shorthandg 123opens issue (or pull request) #123 in the default repositoryg foo/bar /branchesopens the default repository with the/branchespath appendedg z/foo /branchesopens thezerowidth/foo/branchespathg df /branchesopenszerowidth/dotfiles/branchesg /branchesopens the default repository/branches
gi [user|user/repo] [query]: list, search, and open issues/PRs in a repository.gi foo/barlists the issues in thefoo/barrepository.gi foo/bar fixessearches the issues infoo/barfor "fixes".gi(trailing space!) lists the issues in the default repositorygi fixessearches the default repository's issues for "fixes"- The same shorthand expansion applies:
z/foobecomeszerowidth/foo,dfbecomeszerowidth/dotfiles. - Issue search allows the full search syntax , e.g.
gi is:open is:prfor 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 bugopens the new issue page in the default repository with "fix a bug" as the issue titlegn foo/baropens the new issue page in thefoo/barrepository- 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/projectsAnd the following directory tree:
~
├── code
│ ├── dotfiles
│ └── demo
└── work
└── projects
├── client
└── server
ge dfopens thedotfilesproject with the configured editor.gt dfopens the terminal in thedotfilesdirectory.ge wpcopens the editor withwork/projects/client.gt wpcopens the terminal inwork/projects/client.
Both the gt and ge commands have single character aliases: t and e respectively.
girretrieves 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/1on the clipboard becomesgithub/linguist#1- The
gmlcommand retrieves a GitHub URL from the clipboard and converts it to a markdown link:https://github.com/github/linguist/issues/1on the clipboard becomes[github/linguist#1](https://github.com/github/linguist/issues/1) - The
gmdcommand 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/1becomes[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:
//girand//irinsert an issue reference//gmland//mlinsert a markdown link//mdand//mdinsert a markdown link with description when RPC is enabled
gcopens an editor for~/.gh-shorthand.ymlto make it easy to adjust the configuration. See thegh-shorthandconfiguration docs for more information.
Most repository/issue Alfred results include alternate actions:
cmd-cto copy the url to the result- hold
cmdto insert a markdown link - hold
optto insert an issue reference - hold
ctrlto 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.