3 ###############################################################################
6 # Author : Chris Koeritz #
7 # Rights : Copyright (C) 2000-$now by Author #
11 # Provides a somewhat stylized directory lister. #
13 ###############################################################################
14 # This program is free software; you can redistribute it and/or modify it #
15 # under the terms of the GNU General Public License as published by the Free #
16 # Software Foundation; either version 2 of the License or (at your option) #
17 # any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a #
18 # version of the License. Please send any updates to "fred@gruntose.com". #
19 ###############################################################################
21 require "filename_helper.pl";
23 use Env qw($TMP $color_add $ls_dot_add $TERM);
25 local($chewed_line) = "";
27 local($print_list) = "";
29 # if there were no parameters, we make the default listing for the current
32 $print_list = "Current Directory";
35 local(@munged_list) = &patch_name_for_pc(&remove_trailing_slashes(@ARGV));
36 $print_list = "@munged_list";
37 @arg_list = &glob_list(@ARGV);
40 # add parameters to our chewed_line, but skip items if they are flags we don't
42 foreach $dir (@arg_list) {
43 if ($dir eq "-al") { next; } # skip ls directives.
44 if ($dir eq "-l") { next; } # skip ls directives.
45 $chewed_line = $chewed_line . " \"$dir\"";
48 if ("$chewed_line" eq "") {
49 print "No files matched that path specification.\n";
53 # show the header, now that we know there's something to print.
54 print "[" . $print_list . "]\n\n";
56 local($temp_file)=`mktemp "$TMP/zz_frdsumdir.XXXXXX"`;
59 # drop the main payload, the list of directory info, but also save that
60 # info to a file for analysis.
61 system("ls -HhlF $ls_dot_add $color_add $chewed_line");
62 system("ls -HhlF $ls_dot_add $color_add $chewed_line > $temp_file");
63 # the color_add variable, if defined, will have flags for setting the
64 # directory listing color scheme.
68 # open the file and process the lines to get file lengths.
69 open(DIRLIST, "<$temp_file");
70 # we only want to match ls -al style output lines, and only want to keep the size.
71 $pattern="^[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +([0-9.]+[KMG]?).*\$";
72 foreach $file_line (<DIRLIST>) {
73 if ($file_line =~ /$pattern/) {
74 (local $munged = $file_line) =~ s/$pattern/\1/;
75 if ($munged =~ /K$/) {
78 #print "K munged is now $munged\n";
80 if ($munged =~ /M$/) {
82 $munged *= 1024.0 * 1024.0;
83 #print "M munged is now $munged\n";
85 if ($munged =~ /G$/) {
87 $munged *= 1024.0 * 1024.0 * 1024.0;
88 #print "G munged is now $munged\n";
94 unlink($temp_file); # clean up.
96 local($total)=int($lengths);
97 local($kbytes)=int($total / 102.4) / 10;
98 local($mbytes)=int($kbytes / 102.4) / 10;
99 local($gbytes)=int($mbytes / 102.4) / 10;
102 # print a fancy listing showing bytes at least, but only showing mb and gb if appropriate.
103 print "These files occupy $total bytes ($kbytes KB";
105 print " / $mbytes MB";
108 print " / $gbytes GB";
112 print "Overall Drive Usage (megs):\n";
114 system("df -m $chewed_line >$temp_file");
116 # now eat the file again, but this time to get drive space info.
117 open(DIRLIST, "<$temp_file");
118 local($space_info) = "";
119 local($did_title) = 0; # true if we have printed the title by now.
120 foreach $file_line (<DIRLIST>) {
121 ($space_info = $file_line) =~ s/[^ ]* *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *.*$/\1 \2 \3 \4/;
123 # if the title hasn't been printed yet, we take some of the info out of
124 # the line and use it for the right sense of the last column.
125 print "Total Used Free ";
126 $space_info =~ s/[^ ]* *[^ ]* *[^ ]* *([^ ]*)/\1/;
133 unlink($temp_file); # clean up.
135 print "$space_info\n";