8000 ls: set default quoting style to literal when not TTY by RenjiSann · Pull Request #5553 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ls: set default quoting style to literal when not TTY #5553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,9 @@ fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> Quot
QuotingStyle::C {
quotes: quoting_style::Quotes::Double,
}
} else if options.get_flag(options::DIRED) {
} else if options.get_flag(options::DIRED) || !std::io::stdout().is_terminal() {
// By default, `ls` uses Literal quoting when
// writing to a non-terminal file descriptor
QuotingStyle::Literal { show_control }
} else {
// TODO: use environment variable if available
Expand Down
22 changes: 13 additions & 9 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2453,13 +2453,16 @@ fn test_ls_quoting_style() {
{
at.touch("one\ntwo");
at.touch("one\\two");
// Default is shell-escape
// Default is literal, when stdout is not a TTY.
// Otherwise, it is shell-escape
scene
.ucmd()
.arg("--hide-control-chars")
.arg("one\ntwo")
.succeeds()
.stdout_only("'one'$'\\n''two'\n");
.stdout_only("one?two\n");
// TODO: TTY-expected output, find a way to check this as well
// .stdout_only("'one'$'\\n''two'\n");

for (arg, correct) in [
("--quoting-style=literal", "one?two"),
Expand Down Expand Up @@ -2546,7 +2549,9 @@ fn test_ls_quoting_style() {
.ucmd()
.arg("one two")
.succeeds()
.stdout_only("'one two'\n");
.stdout_only("one two\n");
// TODO: TTY-expected output
// .stdout_only("'one two'\n");

for (arg, correct) in [
("--quoting-style=literal", "one two"),
Expand Down Expand Up @@ -2609,7 +2614,9 @@ fn test_ls_quoting_and_color() {
.arg("--color")
.arg("one two")
.succeeds()
.stdout_only("'one two'\n");
.stdout_only("one two\n");
// TODO: TTY-expected output
// .stdout_only("'one two'\n");
}

#[test]
Expand Down Expand Up @@ -3141,11 +3148,8 @@ fn test_ls_path() {
.stdout_is(expected_stdout);

let abs_path = format!("{}/{}", at.as_string(), path);
let expected_stdout = if cfg!(windows) {
format!("\'{abs_path}\'\n")
} else {
format!("{abs_path}\n")
};
let expected_stdout = format!("{abs_path}\n");

scene.ucmd().arg(&abs_path).run().stdout_is(expected_stdout);

let expected_stdout = format!("{path}\n{file1}\n");
Expand Down
0