From: Kaxandra Labat Date: Sun, 17 Jun 2018 03:45:33 +0000 (-0700) Subject: ls: ignore case when coloring file extensions X-Git-Tag: v8.30~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24053fbd8f9bd3639e5afd88d97d7b4bd35f61f5;p=thirdparty%2Fcoreutils.git ls: ignore case when coloring file extensions * 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. --- diff --git a/NEWS b/NEWS index 8f4aefa9c9..1122cf0606 100644 --- 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 diff --git a/src/dircolors.hin b/src/dircolors.hin index 18381a7f69..cc97e291c9 100644 --- a/src/dircolors.hin +++ b/src/dircolors.hin @@ -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 diff --git a/src/ls.c b/src/ls.c index bae2c11041..bf0c5941d7 100644 --- 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; } } diff --git a/tests/local.mk b/tests/local.mk index 1f8b189c23..528f9e5331 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -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 index 0000000000..b3c9e8021f --- /dev/null +++ b/tests/ls/color-ext.sh @@ -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 . + +. "${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