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 5d689e2
Showing 1 changed file with 12 additions and 0 deletions.
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 5d689e2

Please sign in to comment.