Skip to content

Support gh pr create --browse --copy as in hub to open and copy PRs #1646

Open

Description

@gibfahn

Describe the feature or problem you’d like to solve

hub pull-request --help has the following:

 -o, --browse
     Open the new pull request in a web browser.

 -c, --copy
     Put the URL of the new pull request to clipboard instead of printing it.

This is really useful for navigating to or sharing the PR URL after creation.

It would be great to support similar flags.

Proposed solution

Do the same thing in gh.

Activity

  1. added
    enhancement
    on Sep 9, 2020
  2. changed the title [-]Support `gh pr create --browse --copy` as in hub[/-] [+]Support `gh pr create --browse --copy` as in hub to open and copy PRs[/+] on Sep 9, 2020
  3. mislav commented on Sep 9, 2020

    @mislav
    Contributor

    Thank you! This was proposed months ago, but we decided to not incorporate it back then #478 (comment)

    We might revisit this now. I'll leave open to gather feedback. 🙇

  4. gibfahn commented on Sep 9, 2020

    @gibfahn
    Author

    If the answer is gh aliases that seems reasonable, but for cross-platform copying that starts to get complex.

  5. added
    needs-design
    on Oct 7, 2020
  6. ElijahLynn commented on Mar 4, 2021

    @ElijahLynn

    I would really like to see this too, as I miss it greatly after migrating from hub. My use case mainly is that I want to create a PR in the CLI and then open it to add screenshots to it and now I have to click the link whereas with --browse it "just worked". I didn't know about --copy but would like that too, and would use it a lot as I use the copyq clipboard manager and would be great to have the PR URL automatically added to my clipboard stack.

  7. jrogov commented on Mar 19, 2021

    @jrogov

    As a dirty workaround, bash function/script may be used (OSX in example):

    gh() {
        CLIPBOARD_CAPTURE_COMMAND=pbcopy
    
        exec 42>&1
        IFS='' output="$(/usr/bin/env gh "$@" | tee >(cat - >&42))"
        exec 42<&-
        case "$output" in
            (https://github.com*|a[[:space:]]pull[[:space:]]request[[:space:]]for[[:space:]]branch*already[[:space:]]exists*)
                echo "$output" | tail -n1 | $CLIPBOARD_CAPTURE_COMMAND;
                echo "PR URL is copied to clipboard"
        esac
    }
    

    Note: interactive features of gh (e.g. progress of creating a PR) are lost.

    Similarly, open $url can be used to open the PR itself.

  8. added
    core
    and removed
    needs-design
    on Mar 9, 2022
  9. mislav commented on Mar 9, 2022

    @mislav
    Contributor

    We've talked about this and we're generally in favor of adding this functionality to any command that otherwise prints a URL for the created record to standard output.

    I suspect that this would involve creating a new flags helper similar to this:

    func AddJSONFlags(cmd *cobra.Command, exportTarget *Exporter, fields []string) {
    f := cmd.Flags()
    f.StringSlice("json", nil, "Output JSON with the specified `fields`")
    f.StringP("jq", "q", "", "Filter JSON output using a jq `expression`")
    f.StringP("template", "t", "", "Format JSON output using a Go template")

    And a new "exporter" similar to this:

    cli/pkg/cmd/pr/view/view.go

    Lines 118 to 119 in e361fd4

    if opts.Exporter != nil {
    return opts.Exporter.Write(opts.IO, pr)

    Alternatively, this could all be handled on the IOStreams level; for example:

    opts.IO.OutputURL(newURL)
    //=> prints, copies, or browses the URL, depending on flags
  10. jlorenzen commented on Apr 18, 2022

    @jlorenzen

    I would also love to see the option to support opening the PR after creation. One of the biggest features I miss from hub.

  11. tjtrabue commented on Apr 18, 2022

    @tjtrabue

    I would love to see these options supported in GitHub’s CLI! They are features I’ve hacked together myself with shell functions, but having them available as first class features would be much appreciated.

  12. gibfahn commented on Apr 21, 2022

    @gibfahn
    Author

    +1 to hacking things together with shell functions, my gh pr wrapper is getting a bit excessively long at this point 😁

    (https://github.com/gibfahn/dot/blob/main/dotfiles/bin/git-pr)

  13. bag-man commented on May 5, 2022

    @bag-man

    +1 this would be lovely!

  14. danielnolan commented on May 12, 2022

    @danielnolan

    Having the ability to copy the pr url to the clipboard when opening a pr from the command line is one of the biggest things I miss from Hub

  15. added
    gh-pr
    on Oct 2, 2023
  16. sheharyarn commented on May 20, 2024

    @sheharyarn

    Bump. I'm trying to switch to gh from hub, and would really to like to have the --copy flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreenhancementgh-pr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions