| 1 | #!perl | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Open a browser window with the GitHub URL of the repository which you are currently inside of | ||||||||||
| 4 | # PODNAME: gh-open | ||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Browser::Open qw( open_browser ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Getopt::Long qw( GetOptions ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Git::Helpers qw( https_remote_url ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Pod::Usage qw(pod2usage); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | my $branch; | |||||||||
| 15 | my $echo; | ||||||||||
| 16 | 1 | my $help; | |||||||||
| 17 | 1 | my $version; | |||||||||
| 18 | |||||||||||
| 19 | 1 | GetOptions( | |||||||||
| 20 | branch => \$branch, echo => \$echo, help => \$help, | ||||||||||
| 21 | version => \$version, | ||||||||||
| 22 | ); | ||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | if ($help) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | pod2usage(1); | |||||||||
| 26 | 0 | exit(0); | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | if ($version) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | print $Git::Helpers::VERSION, "\n"; | |||||||||
| 31 | 0 | exit(0); | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | # https_remote_url( $remote_name, $use_current_branch ) | ||||||||||
| 35 | 1 | my $url = https_remote_url( shift @ARGV, $branch ); | |||||||||
| 36 | 1 | ▶ | die "No browsable URL found for this remote\n" unless $url; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | ▶ | if ($echo) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | print $url, "\n"; | |||||||||
| 39 | } | ||||||||||
| 40 | else { | ||||||||||
| 41 | 0 | open_browser($url); | |||||||||
| 42 | } | ||||||||||
| 43 | 0 | exit; | |||||||||
| 44 | |||||||||||
| 45 | __END__ | ||||||||||