From 46558889ab823d9423510f449a87a98fd0e3a0b0 Mon Sep 17 00:00:00 2001 From: GTimothy <22472919+GTimothy@users.noreply.github.com> Date: Sun, 16 Feb 2025 16:50:20 +0100 Subject: [PATCH 1/2] unexpand: add -f short alias for --first-only add the `--first-only` alias `-f` expected by busybox. document the change. Co-authored-by: Sylvestre Ledru --- docs/src/extensions.md | 5 +++++ src/uu/unexpand/src/unexpand.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/docs/src/extensions.md b/docs/src/extensions.md index 81457c29d7e..6f394d4901a 100644 --- a/docs/src/extensions.md +++ b/docs/src/extensions.md @@ -193,3 +193,8 @@ Just like on macOS, `base32/base64/basenc` provides `-D` to decode data. ## `shred` The number of random passes is deterministic in both GNU and uutils. However, uutils `shred` computes the number of random passes in a simplified way, specifically `max(3, x / 10)`, which is very close but not identical to the number of random passes that GNU would do. This also satisfies an expectation that reasonable users might have, namely that the number of random passes increases monotonically with the number of passes overall; GNU `shred` violates this assumption. + +## `unexpand` + +GNU `unexpand` provides `--first-only` to convert only leading sequences of blanks. We support a +second way: `-f` like busybox. diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 8956da4e588..c5c4327a585 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -175,6 +175,7 @@ pub fn uu_app() -> Command { ) .arg( Arg::new(options::FIRST_ONLY) + .short('f') .long(options::FIRST_ONLY) .help(get_message("unexpand-help-first-only")) .action(ArgAction::SetTrue), From 2fa89ca6b7fbebf11338b6f03264f2db243e3c1d Mon Sep 17 00:00:00 2001 From: GTimothy <22472919+GTimothy@users.noreply.github.com> Date: Thu, 19 Jun 2025 19:55:04 +0200 Subject: [PATCH 2/2] unexpand: add test for `-f` alias add two tests for the `-f` alias --- tests/by-util/test_unexpand.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/by-util/test_unexpand.rs b/tests/by-util/test_unexpand.rs index 8b447ecdb5f..ed983ca7668 100644 --- a/tests/by-util/test_unexpand.rs +++ b/tests/by-util/test_unexpand.rs @@ -95,6 +95,24 @@ fn unexpand_first_only_1() { .stdout_is("\t\t A B"); } +#[test] +fn unexpand_first_only_2() { + new_ucmd!() + .args(&["-t3", "-f"]) + .pipe_in(" A B") + .succeeds() + .stdout_is("\t\t A B"); +} + +#[test] +fn unexpand_first_only_3() { + new_ucmd!() + .args(&["-f", "-t8"]) + .pipe_in(" A B") + .succeeds() + .stdout_is("\tA B"); +} + #[test] fn unexpand_trailing_space_0() { // evil