line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::PS1::Plugin::Directory; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2011-06-21 09:48:32 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1138
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
10
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
11
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
12
|
1
|
|
|
1
|
|
17
|
use Data::Dumper qw/Dumper/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
13
|
1
|
|
|
1
|
|
6
|
use English qw/ -no_match_vars /; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
14
|
1
|
|
|
1
|
|
414
|
use Path::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
747
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.08; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub directory { |
19
|
0
|
|
|
0
|
1
|
|
my ($self, $options) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $dir = path('.')->absolute; |
22
|
0
|
|
|
|
|
|
my $home = path($ENV{HOME}); |
23
|
0
|
|
|
|
|
|
my $dir_display = "$dir"; |
24
|
0
|
|
0
|
|
|
|
$options->{dir_length} ||= 30; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if ($home->subsumes($dir) ) { |
27
|
0
|
|
|
|
|
|
$dir_display =~ s/$home/~/xms; |
28
|
|
|
|
|
|
|
} |
29
|
0
|
0
|
|
|
|
|
if (length $dir_display > $options->{dir_length}) { |
30
|
0
|
|
|
|
|
|
$dir_display = '...' . substr $dir_display, -$options->{dir_length}, $options->{dir_length}; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
0
|
|
|
|
|
if ($options->{abreviate}) { |
33
|
0
|
|
|
|
|
|
$dir_display =~ s{/([^/])[^/]+/}{/$1/}g; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $len = length $dir_display; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my @details = ( $len, $self->colour('dir_name') . $dir_display ); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my @children = $dir->children; |
41
|
0
|
|
|
|
|
|
my $dir_count = 0; |
42
|
0
|
|
|
|
|
|
my $file_count = 0; |
43
|
0
|
|
|
|
|
|
my $size = 0; |
44
|
0
|
|
|
|
|
|
for my $file (@children) { |
45
|
0
|
0
|
|
|
|
|
if ( -d $file ) { |
46
|
0
|
|
|
|
|
|
$dir_count++; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
|
|
|
|
|
$file_count++; |
50
|
0
|
|
0
|
|
|
|
$size += -s $file || 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
$size |
54
|
0
|
0
|
|
|
|
|
= $size > 10_000_000_000 ? sprintf "%dGiB" , $size / 2**30 |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
55
|
|
|
|
|
|
|
: $size > 900_000_000 ? sprintf "%.1dGiB", $size / 2**30 |
56
|
|
|
|
|
|
|
: $size > 10_000_000 ? sprintf "%dMiB" , $size / 2**20 |
57
|
|
|
|
|
|
|
: $size > 900_000 ? sprintf "%.1dMiB", $size / 2**20 |
58
|
|
|
|
|
|
|
: $size > 10_000 ? sprintf "%dKiB" , $size / 2**10 |
59
|
|
|
|
|
|
|
: $size > 900 ? sprintf "%.1dKiB", $size / 2**10 |
60
|
|
|
|
|
|
|
: $size; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $dir_length = 0; |
63
|
0
|
|
|
|
|
|
my $file_length = 0; |
64
|
0
|
|
|
|
|
|
my $size_length = 0; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
if (!defined $options->{dir} || $options->{dir}) { |
67
|
0
|
|
|
|
|
|
$dir_length = 6 + length $dir_count; |
68
|
0
|
|
|
|
|
|
$dir_count = $self->colour('dir_label') . " dir:" . $self->colour('dir_size') . "$dir_count,"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
0
|
|
|
|
|
|
$dir_count = ''; |
72
|
|
|
|
|
|
|
} |
73
|
0
|
0
|
0
|
|
|
|
if (!defined $options->{file} || $options->{file}) { |
74
|
0
|
|
|
|
|
|
$file_length = 7 + length $file_count; |
75
|
0
|
|
|
|
|
|
$file_count = $self->colour('dir_label') . " file:" . $self->colour('dir_size') . "$file_count,"; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
|
|
|
|
|
$file_count = ''; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
0
|
0
|
|
|
|
if (!defined $options->{size} || $options->{size}) { |
81
|
0
|
|
|
|
|
|
$size_length = 1 + length $size; |
82
|
0
|
|
|
|
|
|
$size = $self->colour('dir_label') . " " . $self->colour('dir_size') . $size; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
0
|
|
|
|
|
|
$size = ''; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $arb = @{$self->parts} + $self->parts_size; |
|
0
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ( $details[0] + $dir_length + $file_length + $size_length + $arb < $self->cols ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$details[0] += $dir_length + $file_length + $size_length; |
91
|
0
|
|
|
|
|
|
$details[1] .= $dir_count . $file_count . $size; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ( $details[0] + $file_length + $size_length + $arb < $self->cols ) { |
94
|
0
|
|
|
|
|
|
$details[0] += $file_length + $size_length; |
95
|
0
|
|
|
|
|
|
$details[1] .= $file_count . $size; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif ( $details[0] + $size_length + $arb - 5 < $self->cols ) { |
98
|
0
|
|
|
|
|
|
$details[0] += $size_length; |
99
|
0
|
|
|
|
|
|
$details[1] .= $size; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
return $self->surround(@details); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 NAME |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
App::PS1::Plugin::Directory - Current directory information |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 VERSION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This documentation refers to App::PS1::Plugin::Directory version 0.08. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SYNOPSIS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
use App::PS1::Plugin::Directory; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Brief but working code example(s) here showing the most common usage(s) |
122
|
|
|
|
|
|
|
# This section will be as far as many users bother reading, so make it as |
123
|
|
|
|
|
|
|
# educational and exemplary as possible. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 DESCRIPTION |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head3 C<directory ()> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns info about the current directory's name size files and subdirectories. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
There are no known bugs in this module. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Patches are welcome. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 AUTHOR |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Copyright (c) 2011 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW, Australia 2077) |
157
|
|
|
|
|
|
|
All rights reserved. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
160
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
161
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
162
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
163
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |