$HOME/binにあるスクリプトを晒してみる
前は$HOME/.zshrcとかに書いてたんだけど、bashでも使えるようにシェルスクリプトにしてみた。
cygwinも使うので、なるべくcygwinでも問題なく動くようになってるはず・・・
あと説明めんどいので一行だけ。
catjp
日本語で表示する。
#!/bin/sh if [ $(uname -o) = "Cygwin" ]; then encoding="windows" else encoding="unix" fi while getopts e: opt; do case $opt in "e" ) encoding="$OPTARG" ;; * ) usage ; exit 0 ;; esac done cat $* | nkf --$encoding
cpan-uninst
ここのを整形しただけです。
まったく同じです。id:holidays-lさんに感謝。
#!/usr/bin/env perl use ExtUtils::Install; use ExtUtils::Installed; unshift @ARGV,new ExtUtils::Installed; sub a{ \@ARGV } uninstall( ( eval { a->[0]->packlist(a->[1]) } || do { require CPAN; a->[0]->packlist( CPAN::Shell->expandany(a->[1])->distribution->base_id =~m/(.*)-[^-]+$/ ); } )->packlist_file, 1, a->[2] )
findbin
$PATHを列挙するだけのもの。
コマンドを探す時とか
findbin | grep <コマンド>
とかいろいろ応用が効いて便利。
#!/bin/sh IFS=: for i in $PATH; do find $PATH; done | sort | uniq
hatebu-backup
#!/usr/bin/env perl use strict; use warnings; use utf8; use DateTime; use Digest::SHA1 qw(sha1); use Getopt::Long qw(:config pass_through auto_help); # pass through unrecognized options. use HTTP::Request; use LWP::UserAgent; use MIME::Base64 qw(encode_base64); use Perl6::Say; use Pod::Usage; use Term::ReadPassword; # set default. %ARGV = ( file => 'hatebu.bmk', mode => 'atom', output => 'hatebu.bmk', password => undef, username => undef, ); GetOptions( 'file=s' => \$ARGV{file}, 'mode=s' => \$ARGV{mode}, 'output=s' => \$ARGV{output}, 'password=s' => \$ARGV{password}, 'username=s' => \$ARGV{username}, ); if ($ARGV{mode} !~ /^(atom|rss|bookmarks)$/) { warn "warning: --mode: use default.\n"; $ARGV{mode} = "atom"; } # set default unless (defined $ARGV{username}) { print "put your hatena username:"; chomp( $ARGV{username} = <STDIN> ); } until (defined $ARGV{password}) { $ARGV{password} = read_password( "put your password:" ); } import_hatena_bookmark(\%ARGV); warn "$ARGV{file}: Can't import hatena bookmarks\n" unless (-f $ARGV{file}); sub import_hatena_bookmark { my $data = shift; # wsse authentication my $nonce = sha1(sha1(time() . {} . rand() . $$)); my $now = DateTime->now->iso8601 . 'Z'; my $digest = encode_base64(sha1($nonce . $now . $data->{password} || ''), ''); my $credentials = sprintf(qq(UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"), $data->{username}, $digest, encode_base64($nonce, ''), $now); my $url = 'http://b.hatena.ne.jp/dump' . ($data->{mode} eq "atom" ? "" : "?mode=" . $data->{mode}); my $req = HTTP::Request->new(GET => $url); $req->header(Accept => 'application/x.atom+xml, application/xml, text/xml, */*'); $req->header('X-WSSE' => $credentials); # saving data my $ua = LWP::UserAgent->new; $ua->show_progress(1); my $res = $ua->request($req); unless ($res->is_success) { die $res->status_line . "\n"; } my $FH = FileHandle->new("> " . $data->{file}) or die sprintf "can't open '%s'.\n", $data->{file}; $FH->print($res->content); $FH->close; } __END__ =head1 NAME hatebu.pl - manipulate hatena bookmarks =head1 SYNOPSIS hatebu.pl [-u username] [-p password] [-f hatena-bookmark-file] [-m mode] [-o output-bookmark-file] [-h] command arg1 arg2 ... =head1 OPTIONS =over 6 =item -u, --user hatena username. =item -p, --pass hatena password. =item -h, --help show help. =item -f, --file default:"hatebu.bmk" hatena bookmark file path. =item -o, --output default:same as --file. output bookmark file path. =item -m, --mode I<modes> default:"atom" modes:"atom", "rss", bookmarks" hatena bookmark file's mode. =back =head1 COMMANDS =over 4 =item help show help. =item add add the URL. =item delete_tag I<tag1> I<tag2> ... delete tags =item replace_tag I<from-tag> I<to-tag> [I<to-tag2> ...] replace tag. =item =back
idm
これは・・・ID managerをwineで動かしてるんだけど
それをidmだけで起動させるためだけに作ったもの。
~/workをsambaで共有させてるのでデータ移行の必要もなし。samba++
#!/bin/sh wine ~/work/wineapp/idm/IDM.exe 1>/dev/null 2>/dev/null &
mkrand
ただランダムな単語(?)を生成するだけのワンライナー。
mkrand 12
とかやれば12桁の単語を生成。
パスワード生成する時に便利。
#!/bin/sh perl -e '@a=(a..z, A..Z, 0..9); map { print $a[int rand @a] } 1..shift' $1
noizy
よくわからない
#!/bin/sh while :; do echo "\a" sleep 0.1 done
ppath
Windowsって「path」だけで$PATHの値表示できていいよね。
そういうものです。
#!/bin/sh perl -MFile::Spec -e 'print join qq(\n), File::Spec->path'
rungui
GUIプログラムを端末から立ち上げる時、色んなデバッグメッセージを吐くのを黙らせるもの。
rungui yumex
という風に使う。
#!/bin/sh command "$@" >/dev/null 2>/dev/null &
sizeofdir
ディレクトリの容量を計算する。
#!/bin/sh command du $1 | \ perl -le 'while (<>) { $total += (split /\s/)[0] } print $total'
title
screenのタイトルを設定します。
このブログから拝借させてもらいました。id:urekatさんありがとうございますm(_ _)m
#!/bin/sh screen -X eval "title '$1'"
wifconfig
これはtaruo.netさんの自分のグローバルIPアドレスを表示するページをそのまま出力してるだけです。
#!/usr/bin/env perl use strict; use warnings; use utf8; use HTML::TreeBuilder; use LWP::Simple 'get'; my $tree = HTML::TreeBuilder->new; $tree->parse(get('http://taruo.net/ip/?')); $tree->eof; print $tree->find('body')->as_text, "\n";