Last active
December 8, 2021 02:42
-
-
Save hellojukay/159a64c376f8c518eb1ed9b9d6ac3248 to your computer and use it in GitHub Desktop.
Revisions
-
hellojukay revised this gist
Dec 8, 2021 . 1 changed file with 60 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,66 @@ #!/usr/bin/env perl use strict; use warnings; use Getopt::Long; GetOptions("p|pipeline" => \(my $pipeline), "h|help" => \(my $help)); sub usage($) { my $code = shift; my $msg = <<EOF; git open [options] open git repo with default browser . -h --help Print help message -p --pipeline Open repo pipelines EOF print($msg); exit($code); } if($help) { usage(0); } # 是否是 github 的仓库 sub is_github_repo ($) { my $url = shift; return $url =~ /github\.com/ ; } # 获取 pipeline 页面的地址 sub pipeline_url (@) { my $url = shift; if(shift) { # github $url .= "/actions"; } else { # gitlab $url .= "/-/pipelines"; } return $url; } # 用默认浏览器打开页面 sub _open ($) { my $url = shift; `/usr/bin/xdg-open $url > /dev/null 2> /dev/null`; } # 获取 origin 地址,转化为 web 页面的地址 my $remote = `git remote -v | grep fetch`; if($remote =~ m/.*?\s+(.*?)\s+.*/) { $remote ="$1"; } $remote = $remote =~ s/\.git$//r; $remote = $remote =~ s/^git@/https:\/\//r; $remote = $remote =~ s/(:)([^\/])/\/$2/r; # 打开 pipeline 地址 if($pipeline) { _open(pipeline_url($remote,is_github_repo($remote))); exit(0); } _open($remote); exit(0); -
hellojukay created this gist
Dec 7, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ #!/usr/bin/env perl my $remote = `git remote -v | grep fetch`; if($remote =~ m/.*?\s+(.*?)\s+.*/) { $remote ="$1"; } $remote = $remote =~ s/git@/https:\/\//r; $remote = $remote =~ s/(:)([^\/])/\/$2/r; system("/usr/bin/xdg-open $remote");