Skip to content

Commit

Permalink
✨ add completion to gh pr checkout <tab> (#714)
Browse files Browse the repository at this point in the history
Hi! I added completion to `gh pr checkout <tab>`
It grabs the first 30 open prs 


![image](https://github.com/nushell/nu_scripts/assets/30557287/755fe63b-dc22-49ef-89c3-27e1ba115d68)

### I tried some things
`gh pr checkout` can accept
- a pr number
- a url
- or a branch

before I tried
- Incrementing the limit of PRs from 30 (default) to 50, but I takes
considerably longer to query, and _gotta go fast_
- using the `extra` field in autocomplete
[`Suggestion`](https://github.com/nushell/reedline/blob/a4bfaa512be8b7214b80c63327930155da86978a/src/completion/base.rs#L58).
But I couldn't make it
- tried to use the `title` in the `value`, like this below, but when you
select a row, it pastes the title into the cli, so `gh pr checkout
<title>` doesn't make sense

![image](https://github.com/nushell/nu_scripts/assets/30557287/1c5caf7c-4653-49ba-afc2-ec8ba155b00f)



So, selecting the pr number is the closest I can get to
  • Loading branch information
AucaCoyan committed Dec 23, 2023
1 parent 54b5a87 commit 703b551
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions custom-completions/gh/gh-completions.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
def "nu-complete gh" [] {
^gh --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -16,7 +16,7 @@ export extern "gh" [
def "nu-complete gh auth" [] {
^gh auth --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -43,7 +43,7 @@ export extern "gh browse" [
def "nu-complete gh codespace" [] {
^gh codespace --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -57,7 +57,7 @@ export extern "gh codespace" [
def "nu-complete gh gist" [] {
^gh gist --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -71,7 +71,7 @@ export extern "gh gist" [
def "nu-complete gh issue" [] {
^gh issue --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -86,7 +86,7 @@ export extern "gh issue" [
def "nu-complete gh org" [] {
^gh org --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -98,12 +98,7 @@ export extern "gh org" [
]

def "nu-complete gh pr" [] {
^gh pr --help
| lines
| filter {|line| str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
^gh pr --help | lines | filter { str starts-with " " } | skip 1 | parse "{value}: {description}" | str trim
}

export extern "gh pr" [
Expand All @@ -112,10 +107,24 @@ export extern "gh pr" [
--help # Show help for command
]

def "nu-complete gh list prs" [] {
gh pr list --json title,number,author,updatedAt | from json | update author {|row| $row.author.login } | rename --column { number: value } | insert description { |row| ( $row.updatedAt | date humanize) + " - " + $row.title + " by " + $row.author } | select value description
}

export extern "gh pr checkout" [
branch_url_or_PRnumber: string@"nu-complete gh list prs" # {<number> | <url> | <branch>}
--branch(-b): string # Local branch name to use (default: the name of the head branch)
--detach # Checkout PR with a detached HEAD
--force(-f) # Reset the existing local branch to the latest state of the pull request
--recurse-submodules # Update all submodules after checkout
--repo(-R) # Select another repository using the [HOST/]OWNER/REPO format
--help # Show help for command
]

def "nu-complete gh project" [] {
^gh project --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -129,7 +138,7 @@ export extern "gh project" [
def "nu-complete gh release" [] {
^gh release --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -144,7 +153,7 @@ export extern "gh release" [
def "nu-complete gh repo" [] {
^gh repo --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand Down Expand Up @@ -213,7 +222,7 @@ export extern "gh repo fork" [
def "nu-complete gh cache" [] {
^gh cache --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -228,7 +237,7 @@ export extern "gh cache" [
def "nu-complete gh run" [] {
^gh run --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -242,7 +251,7 @@ export extern "gh run" [
def "nu-complete gh workflow" [] {
^gh workflow --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -257,7 +266,7 @@ export extern "gh workflow" [
def "nu-complete gh alias" [] {
^gh alias --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand Down Expand Up @@ -306,7 +315,7 @@ export extern "gh completion" [
def "nu-complete gh config" [] {
^gh config --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -320,7 +329,7 @@ export extern "gh config" [
def "nu-complete gh extension" [] {
^gh extension --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -334,7 +343,7 @@ export extern "gh extension" [
def "nu-complete gh gpg-key" [] {
^gh gpg-key --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -348,7 +357,7 @@ export extern "gh gpg-key" [
def "nu-complete gh label" [] {
^gh label --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -363,7 +372,7 @@ export extern "gh label" [
def "nu-complete gh ruleset" [] {
^gh ruleset --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -378,7 +387,7 @@ export extern "gh ruleset" [
def "nu-complete gh search" [] {
^gh search --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -404,7 +413,7 @@ export extern "gh search" [
def "nu-complete gh secret" [] {
^gh secret --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -419,7 +428,7 @@ export extern "gh secret" [
def "nu-complete gh ssh-key" [] {
^gh ssh-key --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand All @@ -440,7 +449,7 @@ export extern "gh status" [
def "nu-complete gh variable" [] {
^gh variable --help
| lines
| filter {|line| str starts-with " " }
| filter { str starts-with " " }
| skip 1
| parse "{value}: {description}"
| str trim
Expand Down

0 comments on commit 703b551

Please sign in to comment.