brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gh alias set turns a long gh command into a short word

CLI
~/tips/tip-cli-gh-alias-set

gh alias set mine 'pr list --author @me'

Saves your favourite gh commands as short aliases, with arguments.

If you type the same gh command with the same flags every day, it can have a name of its own.

An alias expands to a full gh command, and extra arguments are added at the end:

gh alias set mine 'pr list --author @me'
gh mine
gh mine --state merged

Positional placeholders put arguments in a specific spot:

gh alias set bugsby 'issue list --author="$1" --label=bug'
gh bugsby octocat

For anything that needs pipes, use --shell, or start the expansion with !. Then it runs through sh:

gh alias set --shell prs 'gh pr list --json number,title --jq ".[] | .title" | head -5'

gh alias list shows what you have, and the aliases live in gh’s config file, so they move along with your dotfiles. I’d keep them short and lowercase so they feel like built-in subcommands.

Quoting is the tricky part. Single quotes around the expansion keep $1 from being expanded by your own shell when you define it. If you want to change an alias, gh alias set refuses to overwrite one that exists unless you add --clobber. On Windows Command Prompt, the help says you need double quotes instead.

Further reading: gh alias set (GitHub CLI manual)

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link