Skip to content

Commit 5d689e2

Browse files
committed
add zbat wrapper to decompress files automatically
This relies on bsdcat from archive-tools, which supports more formats than just gzip or, failing that, falls back to gunzip -c with a warning. Previously[1], @sharkdp stated that bat would not support compressed files, but would be open in implementing a wrapper. There was another implementation proposed elsewhere[2], but it seems overengineered to me. [1] #642 (comment) [2] #237 (comment)
1 parent dd3d1b8 commit 5d689e2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

bin/zbat

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
set -e
4+
set -u
5+
# shellcheck disable=SC3040
6+
(set -o pipefail 2> /dev/null) && set -o pipefail
7+
8+
cpath="$1"
9+
# cpath without suffix
10+
path="$(echo $cpath | sed 's/\.[^.]*$//')"
11+
12+
( bsdcat "$path" || gunzip -c "$path" ) | batcat --file-name "$path"

0 commit comments

Comments
 (0)