]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: ignore case when coloring file extensions
authorKaxandra Labat <kaxandra.labat@gmail.com>
Sun, 17 Jun 2018 03:45:33 +0000 (20:45 -0700)
committerPádraig Brady <P@draigBrady.com>
Thu, 21 Jun 2018 04:02:30 +0000 (21:02 -0700)
* src/ls.c (get_color_indicator): s/STREQ_LEN/c_strncasecmp/
* src/dircolors.hin: Remove a now redundant entry.
* tests/ls/color-ext.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the change in behavior.

NEWS
src/dircolors.hin
src/ls.c
tests/local.mk
tests/ls/color-ext.sh [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 8f4aefa9c9e91490eabff7b72fa951833aaf35b4..1122cf06069ca74a551d37459b0555e90008a8a1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,8 @@ GNU coreutils NEWS                                    -*- outline -*-
   'cp --force file symlink' now removes the symlink even if
   it is self referential.
 
+  ls --color now matches file extensions case insensitively.
+
 ** New features
 
   md5sum accepts a new option: --zero (-z) to delimit the output lines with a
index 18381a7f69a110dd2eeb77831f0fc2dbfab79fa8..cc97e291c956e748de420761381ac16ad02383d8 100644 (file)
@@ -98,7 +98,6 @@ EXEC 01;32
 .t7z 01;31
 .zip 01;31
 .z   01;31
-.Z   01;31
 .dz  01;31
 .gz  01;31
 .lrz 01;31
index bae2c110412b0b9edce5f6a2ca9ac5e3a2a6b795..bf0c5941d7de699fc5a85d44461ef29192216d9d 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -86,6 +86,7 @@
 
 #include "acl.h"
 #include "argmatch.h"
+#include "c-strcase.h"
 #include "dev-ino.h"
 #include "die.h"
 #include "error.h"
@@ -4766,8 +4767,8 @@ get_color_indicator (const struct fileinfo *f, bool symlink_target)
       for (ext = color_ext_list; ext != NULL; ext = ext->next)
         {
           if (ext->ext.len <= len
-              && STREQ_LEN (name - ext->ext.len, ext->ext.string,
-                            ext->ext.len))
+              && c_strncasecmp (name - ext->ext.len, ext->ext.string,
+                                ext->ext.len) == 0)
             break;
         }
     }
index 1f8b189c23529b9e6b47cc8fe35689d4dbcd90d5..528f9e5331308e4f7b71e5b7d6c539a860bdb8b9 100644 (file)
@@ -583,6 +583,7 @@ all_tests =                                 \
   tests/ls/color-dtype-dir.sh                  \
   tests/ls/color-norm.sh                       \
   tests/ls/color-term.sh                       \
+  tests/ls/color-ext.sh                                \
   tests/ls/dangle.sh                           \
   tests/ls/dired.sh                            \
   tests/ls/file-type.sh                                \
diff --git a/tests/ls/color-ext.sh b/tests/ls/color-ext.sh
new file mode 100755 (executable)
index 0000000..b3c9e80
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+# Ensure "ls --color" properly colorizes file extensions
+
+# Copyright (C) 2018 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ ls
+working_umask_or_skip_
+
+touch img1.jpg IMG2.JPG file1.z file2.Z || framework_failure_
+code_jpg='01;35'
+code_z='01;31'
+c0=$(printf '\033[0m')
+c_jpg=$(printf '\033[%sm' $code_jpg)
+c_z=$(printf '\033[%sm' $code_z)
+
+LS_COLORS="*.jpg=$code_jpg:*.Z=$code_z" ls -U1 --color=always \
+  img1.jpg IMG2.JPG file1.z file2.Z > out || fail=1
+printf "$c0\
+${c_jpg}img1.jpg$c0
+${c_jpg}IMG2.JPG$c0
+${c_z}file1.z$c0
+${c_z}file2.Z$c0
+" > out_ok || framework_failure_
+compare out out_ok || fail=1
+
+
+Exit $fail