changeset 9:2711ab9baa52 default tip

use core module only
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 04 Jan 2021 11:00:54 +0900
parents 38241ae31798
children
files hg-browse
diffstat 1 files changed, 19 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/hg-browse	Mon Jan 04 10:52:36 2021 +0900
+++ b/hg-browse	Mon Jan 04 11:00:54 2021 +0900
@@ -1,40 +1,36 @@
 #!/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;};
+my $push_path = `hg config paths.default`;
 
-if ($@){
-    print "error! >> $stderr";
+if ($?){
+    print "[eror] failed exec hg config paths.default";
     exit 1;
 }
 
 my $open_cmd = $^O eq 'darwin' ? "open" : "xdg-open"; #linux open cmd is xdg-open
 
 # 無かったら特に何もしない
-exit 1 unless ($stdout);
+exit 1 unless ($push_path);
+
 
 # yomitanはパスで開けないので別枠
-if ($stdout =~ /(yomitan)|(chatan)/){
-    yomitan($stdout);
-} elsif ($stdout =~ /firefly/){
-    firefly($stdout);
+my $url;
+
+if ($push_path =~ /(yomitan)|(chatan)/){
+    $url = yomitan($push_path);
+} elsif ($push_path =~ /firefly/){
+    $url = firefly($push_path);
+} else {
+  if ( $push_path =~ m[(https?|ssh)://(\w+@)?(.*)]){
+      $url = "http://$3";
+  }
+  die 'invalid url';
 }
 
-if ( $stdout =~ m[(https?|ssh)://(\w+@)?(.*)]){
-    my $url = "http://$3";
-    @cmd = ($open_cmd,$url);
-    eval { run3 \@cmd,undef,\$stdout,\$stderr;};
-    if ($@){
-        print "error! >> $stderr";
-        exit 1;
-    }
-}
+`$open_cmd $url`;
 
 
 sub yomitan {
@@ -45,9 +41,7 @@
     if ($input =~ m[.*//home/hg/y(\d+)(.+)]){
         $url = $http_domain . "y$1$2";
     }
-    @cmd = ($open_cmd,$url);
-    eval { run3 \@cmd,undef,\$stdout,\$stderr;};
-    exit 0;
+    return $url;
 }
 
 sub firefly {
@@ -57,7 +51,5 @@
     if (($input =~ m[.*?firefly.cr.ie.u-ryukyu.ac.jp/(.*)] )||($input =~  m[.*firefly/(.*)])){
         $url = $http_domain.$1;
     }
-    @cmd = ($open_cmd,$url);
-    eval { run3 \@cmd,undef,\$stdout,\$stderr;};
-    exit 0;
+    return $url;
 }