Skip to content

Commit

Permalink
add zbat wrapper to decompress files automatically
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
anarcat committed Jan 14, 2025
1 parent dd3d1b8 commit a9077f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# unreleased

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

## Bugfixes
* Fix `BAT_THEME_DARK` and `BAT_THEME_LIGHT` being ignored, see issue #3171 and PR #3168 (@bash)
Expand Down
12 changes: 12 additions & 0 deletions bin/zbat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -e
set -u
# shellcheck disable=SC3040
(set -o pipefail 2> /dev/null) && set -o pipefail

cpath="$1"
# cpath without suffix
path="$(echo $cpath | sed 's/\.[^.]*$//')"

( bsdcat "$path" || gunzip -c "$path" ) | batcat --file-name "$path"

0 comments on commit a9077f3

Please sign in to comment.