From 26e51adc9ff4138a7af13f8e16c840fdb13b9253 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Mon, 21 Jan 2013 22:09:50 -0800 Subject: [PATCH] Add script to test dircolors file This Perl script reads a valid dircolors configuration file and prints the colorscheme used by 'ls --color' for each file type (and extension). Error checking is non-existent. The script assumes that your dircolors file is valid input for the dircolors program. --- dircolortest | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 dircolortest diff --git a/dircolortest b/dircolortest new file mode 100755 index 0000000..f5a2db1 --- /dev/null +++ b/dircolortest @@ -0,0 +1,55 @@ +#!/usr/bin/perl +# A utility script to test out dircolors settings without reloading +# Usage: dircolortest + +if ($#ARGV < 0) { + die "Usage: $0 \n"; +} + +if ($#ARGV > 0) { + warn "Ignoring additional command line arguments\n"; +} + +# Open the file and get the handle +open DCFILE, $ARGV[0] or + die "Cannot open dircolors file $ARGV[0]! $!\n"; + +$line_counter = 0; + +while ($line = ) { + chomp $line; + + # Strip off any comments + $line =~ s/#.*$//; + + # Strip off leading and trailing whitespace + $line =~ s/^\s*//; + $line =~ s/\s*$//; + + if ($line ne '') { + ($type, $format) = split /\s+/, $line; + + # Ignore the TERM lines, we don't care about them here + next if ($type eq 'TERM'); + + # Just a little enhancement, if the type begins with a . + if ($type =~ m/^\./) { + $type = "*$type"; + } + + print "\033[${format}m$type\033[m"; + + $line_counter = $line_counter + 1; + + if ($line_counter == 8) { + print "\n"; + $line_counter = 0; + } else { + print "\t"; + } + } +} + +print "\n" if ($line_counter != 0); + +close DCFILE;