changeset 0:78df974566a7

initial commit
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 12 Nov 2018 19:56:42 +0900
parents
children 85f5eada6707
files hg-browse perl-wc
diffstat 2 files changed, 81 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hg-browse	Mon Nov 12 19:56:42 2018 +0900
@@ -0,0 +1,65 @@
+#!/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";
+    print "$url\n";
+    @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[jp//home/hg/y(\d+)(.+)]){
+        $url = $http_domain . "y$1/".$mid_path."y$1".$2;
+    } elsif ($input =~ m[ssh://.*yomitan.*//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/(.*)]){
+        $url = $http_domain.$1;
+    }
+    @cmd = ('open',$url);
+    eval { run3 \@cmd,undef,\$stdout,\$stderr;};
+    exit 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/perl-wc	Mon Nov 12 19:56:42 2018 +0900
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Encode;
+
+my $buffer = do { local $/; <>; };
+
+my $strings = decode_utf8($buffer);
+
+my $lines = $strings =~ s/\n/\n/g || 1;
+my $chars = length($strings);
+my $bytes = length($buffer);
+
+print "lines: $lines\n";
+print "chars: $chars\n";
+print "bytes: $bytes\n";