Skip to content

Commit a9077f3

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 a9077f3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# unreleased
22

33
## Features
4+
* Add a `zbat` wrapper script to automatically decompress files before display, see PR #3177 (@anarcat)
45

56
## Bugfixes
67
* Fix `BAT_THEME_DARK` and `BAT_THEME_LIGHT` being ignored, see issue #3171 and PR #3168 (@bash)

Diff for: 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)