Gentoo Archives: gentoo-commits

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