Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Provide jump option, but this dont work in WSL2
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Jul 28, 2023
1 parent b404a3d commit 5a8f3d7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cmd/nixpkgs-url/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"log"
"os"
"os/exec"
"runtime"

nixurl "github.com/kachick/nixpkgs-url"
)
Expand All @@ -18,6 +20,25 @@ var (
revision = "rev"
)

// https://stackoverflow.com/posts/39324149/revisions
// open opens the specified URL in the default browser of the user.
func open(url string) error {
var cmd string
var args []string

switch runtime.GOOS {
case "windows":
cmd = "cmd"
args = []string{"/c", "start"}
case "darwin":
cmd = "open"
default: // "linux", "freebsd", "openbsd", "netbsd"
cmd = "xdg-open"
}
args = append(args, url)
return exec.Command(cmd, args...).Start()
}

func main() {
const usage = `Usage: nixpkgs-url <subcommand> <flags>
Expand All @@ -31,6 +52,7 @@ $ nixpkgs-url -version`
currentFlag := detectCmd.Bool("current", false, "print current nixpath without bumping")
lastFlag := detectCmd.Bool("last", false, "print git head ref without bumping")
targetFlag := detectCmd.Bool("target", false, "print which file will be bumped")
jumpFlag := detectCmd.Bool("jump", false, "open github URL with current ref")

flag.Usage = func() {
// https://github.com/golang/go/issues/57059#issuecomment-1336036866
Expand Down Expand Up @@ -83,6 +105,14 @@ $ nixpkgs-url -version`
log.Fatalf("Getting the current version has been failed: %s", err.Error())
}
fmt.Println(current)

if *jumpFlag {
err = open("https://github.com/NixOS/nixpkgs/commit/" + current)
if err != nil {
log.Fatalf(err.Error())
}
}

return
}
last, err := nixurl.GetLastVersion()
Expand Down

0 comments on commit 5a8f3d7

Please sign in to comment.