view hg-browse @ 3:f05a6c7471fa

tweak
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sat, 06 Apr 2019 17:34:35 +0900
parents 3656bdd46f54
children
line wrap: on
line source

#!/usr/bin/env perl
use strict;
use warnings;
use IPC::Run3;


# hg config経由でhgrcにかかれているpush先を確認する
my @cmd = ('hg','config','paths.default');
my ($stdout,$stderr);
eval { run3 \@cmd,undef,\$stdout,\$stderr;};

if ($@){
    print "error! >> $stderr";
    exit 1;
}

# 無かったら特に何もしない
exit 1 unless ($stdout);

# yomitanはパスで開けないので別枠
if ($stdout =~ /yomitan/){
    yomitan($stdout);
} elsif ($stdout =~ /firefly/){
    firefly($stdout);
}

if ( $stdout =~ m[(https?|ssh)://(\w+@)?(.*)]){
    my $url = "http://$3";
    @cmd = ('open',$url);
    eval { run3 \@cmd,undef,\$stdout,\$stderr;};
    if ($@){
        print "error! >> $stderr";
        exit 1;
    }
}


sub yomitan {
    my $input  = shift;
    my $http_domain = 'https://ie.u-ryukyu.ac.jp/hg/';
    my $mid_path = 'index.cgi/home/hg/';
    my $url;

    if ($input =~ m[.*//home/hg/y(\d+)(.+)]){
        $url = $http_domain . "y$1/".$mid_path."y$1".$2;
    }
    @cmd = ('open',$url);
    eval { run3 \@cmd,undef,\$stdout,\$stderr;};
    exit 0;
}

sub firefly {
    my $input  = shift;
    my $http_domain = 'http://www.cr.ie.u-ryukyu.ac.jp/';
    my $url;
    if (($input =~ m[.*?firefly.cr.ie.u-ryukyu.ac.jp/(.*)] )||($input =~  m[.*firefly/(.*)])){
        $url = $http_domain.$1;
    }
    @cmd = ('open',$url);
    eval { run3 \@cmd,undef,\$stdout,\$stderr;};
    exit 0;
}