]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Change zstdless behavior to align with zless (#2909)
authorbinhdvo <binhvo@gmail.com>
Sat, 22 Jan 2022 00:57:19 +0000 (19:57 -0500)
committerGitHub <noreply@github.com>
Sat, 22 Jan 2022 00:57:19 +0000 (19:57 -0500)
* Change zstdless behavior to align with zless

programs/zstdless
tests/playTests.sh

index 893799e7d95a06738e3805df931689a09d293a4b..17726a4f6e1efb5328d0f2c116f20500149db41b 100755 (executable)
@@ -1,2 +1,8 @@
 #!/bin/sh
-zstdcat "$@" | less
+
+zstd=${ZSTD:-zstd}
+
+# TODO: Address quirks and bugs tied to old versions of less, provide a mechanism to pass flags directly to zstd
+
+export LESSOPEN="|-${zstd} -cdfq %s"
+exec less "$@"
index 78d8e742aa31e4d36774c6cd1da100317cd795bd..f19291a6063e798ed424b287e6583c96650b8368 100755 (executable)
@@ -89,6 +89,7 @@ PRGDIR="$SCRIPT_DIR/../programs"
 TESTDIR="$SCRIPT_DIR/../tests"
 UNAME=$(uname)
 ZSTDGREP="$PRGDIR/zstdgrep"
+ZSTDLESS="$PRGDIR/zstdless"
 
 detectedTerminal=false
 if [ -t 0 ] && [ -t 1 ]
@@ -322,6 +323,20 @@ ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst && die "Should have fail
 ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst | grep "No such file or directory" || true
 rm -f tmp_grep*
 
+println "\n===> zstdless tests"
+if [ -n "$(which less)" ]; then
+  ln -sf "$ZSTD_BIN" zstd
+  rm -f tmp_less*
+  echo "1234" > tmp_less
+  zstd -f tmp_less
+  lines=$(ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less.zst | wc -l)
+  test 1 -eq $lines
+  ZSTD=./zstd "$ZSTDLESS" -f tmp_less.zst > tmp_less_regenerated
+  $DIFF tmp_less tmp_less_regenerated
+  ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || die
+  rm -f tmp_less*
+fi
+
 println "\n===>  --exclude-compressed flag"
 rm -rf precompressedFilterTestDir
 mkdir -p precompressedFilterTestDir