App-dufolder

 view release on metacpan or  search on metacpan

dufolder  view on Meta::CPAN

# use 5.030 ; 
use strict ; 
use warnings ; 
use feature qw [ say state ] ;
use Cwd ; 
use File::Spec ; 
use Getopt::Std ; getopts '.,:b:i:l:B:G:' , \my %o ; 
use List::Util qw[ max sum0 ] ;
use POSIX qw [ strftime ] ; 
use Term::ANSIColor qw[ :constants ] ; $Term::ANSIColor::AUTORESET = 1 ;
binmode STDOUT , ':utf8' ;

$o{b} //= 512 ; # stat関数で1個のファイルのブロック数を得た場合に、それを何倍したら、ディスクを占有するバイト数になるか。
my $optI0 = 0 eq ($o{i} // '' ) ; # -i0の指定があるか否か。 inodeで一致するものは1個しか受け付けないようにする。
my $optL0 = 0 eq ($o{l} // '' ) ; # -l0の指定があるか否か。stat 関数を使うか lstat 関数を使うかを指定。
my $optc0 = 0 eq ($o{','}//'' ) ; # -,0の指定があるか否か。千進法区切りで,を使うか否かを指定。
$ARGV[0] = '.' if @ARGV == 0 ;

# 特殊な関数

sub d3 ($)  ; # 数を3桁区切りに変換することもできるようにする。# -,0が指定されたら3桁区切りにしない。

dufolder  view on Meta::CPAN

my @files ; # 探索したファイルを収納する。
my @visible ; # 非ドットファイルの全体。
my $d0 = cwd ; 
& getFiles ( $_ , \@files , \@visible ) for @ARGV ; 
if ( exists $o{B} ) { & fileDimTable ( $o{'.'} ? @files : @visible ) ; exit } 

& prepCommands ( \@files , \@visible , $datetime, my $msg , my $change , my $cmd1 , my $cmd2 ) ; # change はファイルの変更個数, 
do { say $msg ; exit } unless exists $o{G} ; # -Gの指定があればさらに続く。
if ( $o{G} =~ /0/ ) { say "$cmd1\n$cmd2" } ; # -Gに0があれば、コマンド文を表示
if ( $o{G} =~ /1/ ) { & againCheck ( $change ) and exit } ; # -G に1があれば、もしも前のコミットでこのコマンドでコミット済みなら終了。
if ( $o{G} =~ /[12]/ ) { do { my $out2 = qx[$cmd2] ; binmode STDOUT , ':raw' ; say "-- ->", BOLD $out2 //'' } } ; # コミット実行! 
exit ; 

# 上記を構造化するために切り出した関数

sub getFiles ( $ $$ ) { 
  state $inodes ;
  state $c2 = do { File::Spec -> catfile ( '' , '.' ) } ; # ディレクトリ階層の区切りの直後にドットがあるパターン "/."
  my @found = split /\n/ , qx [ find $_[0] ] , 0 ; # find コマンドで見つけたファイルを格納。
  @found = grep { ! $inodes -> { ( xstat $_ ) [ 1 ] } ++ }  @found if ! $optI0 ; # inodeで過去に一致したものは除去する
  push @{ $_[1] } , @found ;



( run in 0.219 second using v1.01-cache-2.11-cpan-eab888a1d7d )