3 #=======================================================================
5 # File ID: dc4436de-5619-11e5-9330-000df06acc56
7 # Read git-annex keys from stdin or files and output total size.
10 # ©opyleft 2015– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
18 use Number
::Bytes
::Human
qw(format_bytes);
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = '0.2.0';
36 Getopt
::Long
::Configure
('bundling');
39 'display|d' => \
$Opt{'display'},
40 'help|h' => \
$Opt{'help'},
41 'quiet|q+' => \
$Opt{'quiet'},
42 'verbose|v+' => \
$Opt{'verbose'},
43 'version' => \
$Opt{'version'},
45 ) || die("$progname: Option error. Use -h for help.\n");
47 $Opt{'verbose'} -= $Opt{'quiet'};
48 $Opt{'help'} && usage
(0);
49 if ($Opt{'version'}) {
62 $total_size += file_size
($_);
63 $Opt{'display'} && print("$total_size ");
67 printf("\n%s: Total size of keys: %u (%s)\n",
70 format_bytes
($total_size, bs
=> 1000),
78 # Read file size from git-annex key {{{
81 if ($key =~ /[A-Z0-9_]+-s(\d+)-/) {
89 # Print program version {{{
90 print("$progname $VERSION\n");
96 # Send the help message to stdout {{{
99 if ($Opt{'verbose'}) {
105 Read git-annex keys from stdin or files and output total size.
109 git-annex unused >unused.txt
112 Usage: $progname [options] [file [files [...]]]
117 Prefix each line with the current count.
121 Be more quiet. Can be repeated to increase silence.
123 Increase level of verbosity. Can be repeated.
125 Print version information.
133 # Print a status message to stderr based on verbosity level {{{
134 my ($verbose_level, $Txt) = @_;
136 if ($Opt{'verbose'} >= $verbose_level) {
137 print(STDERR
"$progname: $Txt\n");
145 # This program is free software; you can redistribute it and/or modify
146 # it under the terms of the GNU General Public License as published by
147 # the Free Software Foundation; either version 2 of the License, or (at
148 # your option) any later version.
150 # This program is distributed in the hope that it will be useful, but
151 # WITHOUT ANY WARRANTY; without even the implied warranty of
152 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
153 # See the GNU General Public License for more details.
155 # You should have received a copy of the GNU General Public License
156 # along with this program.
157 # If not, see L<http://www.gnu.org/licenses/>.
159 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :