Skip to content
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

Change zstdless behavior to align with zless #2909

Merged
merged 5 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 7 additions & 1 deletion programs/zstdless
Original file line number Diff line number Diff line change
@@ -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 "$@"
14 changes: 14 additions & 0 deletions tests/playTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down Expand Up @@ -322,6 +323,19 @@ 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"
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
cat tmp_less_regenerated
binhdvo marked this conversation as resolved.
Show resolved Hide resolved
$DIFF tmp_less tmp_less_regenerated
ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || true
binhdvo marked this conversation as resolved.
Show resolved Hide resolved
rm -f tmp_less*

println "\n===> --exclude-compressed flag"
rm -rf precompressedFilterTestDir
mkdir -p precompressedFilterTestDir
Expand Down