Created
March 21, 2016 14:57
-
-
Save tkm-kj/6bf6c786cce66fcb8dbc to your computer and use it in GitHub Desktop.
指定したユーザのdotfileリポジトリのURLをブラウザで開くスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/google/go-github/github" | |
"github.com/skratchdot/open-golang/open" | |
"log" | |
"os" | |
"regexp" | |
) | |
func isMatch(name string) (match bool, err error) { | |
r, err := regexp.Compile(`[Dd]otfile`) | |
match = r.MatchString(name) | |
return | |
} | |
func main() { | |
client := github.NewClient(nil) | |
opt := &github.RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"} | |
repos, _, err := client.Repositories.List(os.Args[1], opt) | |
if err != nil { | |
log.Fatal(err) | |
} | |
var url string | |
for _, r := range repos { | |
match, err := isMatch(*r.Name) | |
if err != nil { | |
log.Fatal(err) | |
} | |
if match { | |
url = *r.HTMLURL | |
break | |
} | |
} | |
if url == "" { | |
fmt.Println("Dotfile not exist!") | |
} else { | |
open.Run(url) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行コマンド