summaryrefslogtreecommitdiff
blob: 6b895619940660d012f339634a8f3261434699e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--- durep
+++ durep
@@ -14,6 +14,8 @@
 #############################################################################
 
 use Getopt::Long;
+use feature 'switch';
+use Term::ANSIColor qw(:constants);
 use File::Basename;
 use MLDBM qw(DB_File Storable);
 use Fcntl;
@@ -27,6 +29,7 @@
 our ($root_node, $filesystem_id, @stats);
 our ($opt_help, $opt_version, $opt_textdepth, $opt_hidesize, $opt_showdate, $opt_nosort, $opt_quiet);
 our ($opt_savefile, $opt_loadfile, $opt_desc, $opt_collate);
+our ($opt_nocolor);
 our ($opt_files, $opt_onefilesystem, $opt_collapsepath, $opt_excludepath, $opt_coalescefiles);
 our ($root_dir, $file_count, $dir_count, $next_id);
 our ($TYPE_FILE, $TYPE_DIR, $TYPE_EMPTY, $TYPE_COALESCED, $TYPE_COLLAPSED);
@@ -56,6 +59,8 @@
 	    "d|desc=s"            => \$opt_desc,
 	    "c|collate=s"         => \$opt_collate,
 
+	    "nc|nocolor" 	  => \$opt_nocolor,
+
 	    "f|files"             => \$opt_files,
 	    "x|one-file-system"   => \$opt_onefilesystem,
 	    "cp|collapse-path=s"  => \$opt_collapsepath,
@@ -332,13 +337,58 @@
     printf(" [%s%s] ", "#" x $numofchars, " " x (30-$numofchars));
     printf("%6.2f%% ", $percent);
     printf("%s ", shortDate($entry->{MTIME})) if $opt_showdate;
-    printf("%s%s\n", $entry->{NAME}, $entry->{TYPE} & $TYPE_DIR ? "/" : "");
+   
+    printColor( $entry ) unless ( $opt_nocolor );
+    printNoColor( $entry ) if ( $opt_nocolor );
     if($entry->{TYPE} & $TYPE_DIR) {
       printDir($entry, $indent+1) if(!defined $opt_textdepth || ($opt_textdepth > $indent+1));
     }
   }
 }
 
+sub printColor {
+    my $entry = shift;
+    
+    my @tmp = split /\./, $entry->{NAME};
+    
+    if ( $entry->{TYPE} & $TYPE_DIR ) {
+        print BLUE, BOLD, $entry->{NAME}."/\n", RESET
+    }
+    else {
+        given ($tmp[$#tmp]) {
+            #executable (bright green)
+            when([ qw(cmd exe com btm bat sh csh) ]) {
+                print BOLD, GREEN, $entry->{NAME}."\n", RESET
+            }
+            #archives / compressed (bright red)
+            when([ qw(tar tgz arj taz lzh zip z Z gz bz2 tbz2 tz deb rpm rar ace zoo cpio 7z rz) ]) {
+                print BOLD, RED, $entry->{NAME}."\n", RESET 
+            }
+            #image formats
+            when([ qw(jpg jpeg gif bmp ppm tga xbm xpm tif tiff png mng xcf pcx mpg mpeg m2v avi mkv
+                    ogm mp4 mp4v mov qt wmv asf rm rmvb flc fli gl dl) ]) {
+                print BOLD, MAGENTA, $entry->{NAME}."\n", RESET
+            }
+            #misc.
+            when([ qw(pdf ps txt patch diff log tex doc) ]) {
+                print GREEN, $entry->{NAME}."\n", RESET
+            }
+            when([ qw(mp3 wav mid midi au ogg flac aac) ]) {
+                print CYAN, $entry->{NAME}."\n", RESET
+            }
+            default {
+                print $entry->{NAME}."\n", RESET
+            }
+        }
+    }
+}
+
+sub printNoColor {
+    my $entry = shift;
+
+    printf("%s%s\n", $entry->{NAME}, $entry->{TYPE} & $TYPE_DIR ? "/" : "");
+}
+
 sub processSizeOption {
   my ($size, $temp);
 
@@ -438,6 +488,9 @@
    -d, --desc=<description>     give description of save file
    -c, --collate=<dir>          collate save files in dir for web report
 
+Color Option:
+  -nc, --nocolor 		no color output
+  				By default durep color outpu
 Inclusion Options:
    -f, --files                  do not descend into subdirs, only report files
    -x, --one-file-system        do not traverse file systems