string shorten: Don't produce output with --quiet

This would've printed stuff in case it didn't have to shorten (which
means it "failed" because the logic is "did something").

Fixes #12732
This commit is contained in:
Fabian Boehm
2026-05-10 11:16:41 +02:00
parent a9cc505d62
commit 5c6acdee09
2 changed files with 18 additions and 4 deletions

View File

@@ -166,8 +166,11 @@ fn handle(
pos += skip_escapes(&line, pos).max(1);
}
if self.quiet && pos != 0 {
return Ok(());
if self.quiet {
if pos != 0 {
return Ok(());
}
continue;
}
let output = match pos {
@@ -215,8 +218,11 @@ fn handle(
}
}
if self.quiet && pos != line.len() {
return Ok(());
if self.quiet {
if pos != line.len() {
return Ok(());
}
continue;
}
if pos == line.len() {

View File

@@ -1064,6 +1064,14 @@ string shorten -m 2 foo
string shorten -m 5 foobar
# CHECK: foob…
# Should produce no output and return false because there was nothing to shorten.
string shorten -m 2 -q 12
echo $status
# CHECK: 1
string shorten -lm 2 -q 12
echo $status
# CHECK: 1
# Char is longer than width, we truncate instead.
string shorten -m 5 --char ........ foobar
# CHECK: fooba