mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
ls: don't color symlink target
This commit is contained in:
parent
1d7e206d72
commit
4e4c3aba00
2 changed files with 10 additions and 8 deletions
|
@ -1528,13 +1528,8 @@ fn display_file_name(
|
|||
if config.format == Format::Long && metadata.file_type().is_symlink() {
|
||||
if let Ok(target) = path.read_link() {
|
||||
// We don't bother updating width here because it's not used for long
|
||||
let mut target_name = target.to_string_lossy().to_string();
|
||||
if let Some(ls_colors) = &config.color {
|
||||
target_name = color_name(&ls_colors, &target, target_name, metadata);
|
||||
}
|
||||
name.push_str(" -> ");
|
||||
|
||||
name.push_str(&target_name);
|
||||
name.push_str(&target.to_string_lossy());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -639,14 +639,18 @@ fn test_ls_color() {
|
|||
at.touch(&nested_file);
|
||||
at.touch("test-color");
|
||||
|
||||
at.symlink_file(&nested_file, "link");
|
||||
|
||||
let a_with_colors = "\x1b[1;34ma\x1b[0m";
|
||||
let z_with_colors = "\x1b[1;34mz\x1b[0m";
|
||||
let nested_dir_with_colors = "\x1b[1;34mnested_dir\x1b[0m";
|
||||
let link_with_color = "\x1b[1;36mlink\x1b[0m";
|
||||
|
||||
// Color is disabled by default
|
||||
let result = scene.ucmd().succeeds();
|
||||
assert!(!result.stdout_str().contains(a_with_colors));
|
||||
assert!(!result.stdout_str().contains(z_with_colors));
|
||||
assert!(!result.stdout_str().contains(link_with_color));
|
||||
|
||||
// Color should be enabled
|
||||
scene
|
||||
|
@ -654,7 +658,8 @@ fn test_ls_color() {
|
|||
.arg("--color")
|
||||
.succeeds()
|
||||
.stdout_contains(a_with_colors)
|
||||
.stdout_contains(z_with_colors);
|
||||
.stdout_contains(z_with_colors)
|
||||
.stdout_contains(link_with_color);
|
||||
|
||||
// Color should be enabled
|
||||
scene
|
||||
|
@ -662,12 +667,14 @@ fn test_ls_color() {
|
|||
.arg("--color=always")
|
||||
.succeeds()
|
||||
.stdout_contains(a_with_colors)
|
||||
.stdout_contains(z_with_colors);
|
||||
.stdout_contains(z_with_colors)
|
||||
.stdout_contains(link_with_color);
|
||||
|
||||
// Color should be disabled
|
||||
let result = scene.ucmd().arg("--color=never").succeeds();
|
||||
assert!(!result.stdout_str().contains(a_with_colors));
|
||||
assert!(!result.stdout_str().contains(z_with_colors));
|
||||
assert!(!result.stdout_str().contains(link_with_color));
|
||||
|
||||
// Nested dir should be shown and colored
|
||||
scene
|
||||
|
|
Loading…
Reference in a new issue