My Nushell aliases for `gh` command.
Almost everyday I start my work playing with my config. Today I added aliases for gh
to nu.
# List issues related to me
export def ghil [] {
(gh issue list --search "involves:iesahin" --json title,url) | from json
}
# Add a comment to an issue
export alias ghic = gh issue comment
# Create an issue
export alias ghiC = gh issue create $in
# View an issue
export alias ghiv = gh issue view
# View an issue in the browser
export alias ghiw = gh issue view --web
# List PRs in a table
export def ghpl [] {
(gh pr list --json "title,url,headRefName" ) | from json
}
# View a PR
export alias ghpv = gh pr view
# View a PR in Github
export alias ghpw = gh pr view --web
# Checkout a PR
export alias ghco = gh pr checkout
# Add a comment to a PR
export alias ghpc = gh pr comment
# Show changes in a PR
export alias ghpd = gh pr diff
# Add a review to a PR
export alias ghpR = gh pr review
# Create a PR
export alias ghpC = gh pr create
# Merge a PR to main
export alias ghpM = gh pr merge
# List GH CI runs in a table
export def ghrl [] {
(gh run list --json conclusion,displayTitle,headBranch,url ) | from json
}
# View a GH CI run
export alias ghrv = gh run view
# View a GH CI run in the browser
export alias ghrw = gh run view --web
# View output from a failed run
export alias ghrf = gh run view --log-failed
# Search code and get results in a table
export def ghsc [] {
(gh search code $in --json repository,path,textMatches,url) | from json
}
NU
Aliases don’t allow pipes in nushell. Those def
s are because of that.
When there is an $in
parameter in a alias, it expects the input from a pipe. An issue is created like, for example,
$ "Your software sucks" | ghiC
NU
To search the code copied into clipboard and get only the urls, you can use
$ pbpaste | ghsc | get url
NU
To open them in different browser windows,
$ pbpaste | ghsc | get url | each { |u| start $u }
NU
I’ll add a shortcut key for this last one. It’s so quick :D