Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

92.6. bat-0.26.1

Cat clone with syntax highlighting and Git integration

Version 0.26.1, release 1
Shelf cli — Command-line productivity utilities: search, view, navigation and text wrangling in the terminal
Phase 41_system (System), 285 of 1047 in build order
Licence MIT OR Apache-2.0
Homepage https://github.com/sharkdp/bat
Build time 6.4 SBU
Installed size 6.4 MiB in 13 files
Recipe ports/core/cli/bat/kpkgbuild

About

bat is cat with syntax highlighting, line numbers and a Git change gutter. On KDOS it is also the reader of manual pages: /etc/bash.bashrc aliases cat to bat --paging=never --style=plain and, where the port’s pager script exists, sets MANPAGER to it. The syntax and theme sets bat highlights with are compiled during this build, and installed under /usr/share/bat/assets as well, where delta and presenterm take theirs from.

Sources

Dependencies

Depends on: rust, zlib, libgit2, oniguruma.

Required by (2): delta, presenterm.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install bat'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/cli/bat.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/cli/bat
echo '4474de87e084953eefc1120cf905a79f72bbbf85091e30cf37c9214eafcaa9c9  bat-0.26.1.tar.gz' | sha256sum -c -
echo '389113468c82f4c3085c5cb80ad778954e7fcf4bfdf7b42a1acc7ba50870b5d4  bat-vendor-0.26.1.tar.xz' | sha256sum -c -
echo '3d4439126841c3b0d62f3f0985ea17be85912d13092cdc33d5e7bb84f7f7ff2b  bat-assets-0.26.1.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/bat
SRC=$SRC_ROOT/bat-0.26.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf bat-0.26.1.tar.gz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
export BAT_ASSETS_GEN_DIR="$SRC/gen"

tar xf $PORT_SRC/${name}-assets-${version}.tar.xz
for p in assets/patches/*.patch; do
	patch -d assets -p0 < "$p"
done

export RUSTFLAGS="-C target-feature=-crt-static"

cargo build --release --frozen --offline
target/release/bat cache --build --blank --acknowledgements \
	--source=assets --target=assets
cargo build --release --frozen --offline
readelf -d target/release/bat | grep -q 'NEEDED.*\[libgit2\.so\.1\.9\]'
readelf -d target/release/bat | grep -q 'NEEDED.*\[libonig\.so\.5\]'

install -Dm755 target/release/bat $PKG/usr/bin/bat
install -Dm644 gen/assets/manual/bat.1 -t "$PKG/usr/share/man/man1"
install -Dm644 gen/assets/completions/bat.bash "$PKG/usr/share/bash-completion/completions/bat"
install -Dm644 gen/assets/completions/bat.zsh  "$PKG/usr/share/zsh/site-functions/_bat"
install -Dm644 gen/assets/completions/bat.fish "$PKG/usr/share/fish/vendor_completions.d/bat.fish"

install -d "$PKG/usr/libexec/bat"
cat > "$PKG/usr/libexec/bat/man-pager" <<'KDOS_SH'
#!/bin/sh
sed -e 's/\x1b\[[0-9;]*m//g' -e 's/.\x08//g' "$@" | bat -l man -p
KDOS_SH
chmod 755 "$PKG/usr/libexec/bat/man-pager"

install -Dm644 assets/syntaxes.bin assets/themes.bin assets/acknowledgements.bin \
	-t "$PKG/usr/share/bat/assets"
{
	cat LICENSE-MIT
	target/release/bat --no-config --acknowledgements
} > "$PKG/usr/share/bat/assets/acknowledgements.txt"
chmod 644 "$PKG/usr/share/bat/assets/acknowledgements.txt"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/bat, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf bat-0.26.1-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/bat, and runs the triggers its paths call for.

Contents

Installed programs: bat.

Installed directories: /usr/libexec/bat, /usr/share/bat, /usr/share/licenses/bat.

Short descriptions

bat a cat(1) clone with syntax highlighting and Git integration.

Notes

Three archives make the build. The release tarball carries bat’s highlighting sources as empty git submodules; bat-assets-<version>.tar.xz is those submodules at the tag’s pinned commits, cut down to the grammars, themes and licence files the set compiler reads, and no tool writes it, so it is remade by hand on a version bump with the commands in A bundle no tool writes. bat-vendor-<version>.tar.xz holds the crates, from cargo vendor. build.sh unpacks the assets over the empty directories and applies upstream’s own assets/patches to them.

The build runs cargo twice. The first build makes a bat that can compile sets; bat cache --build then writes syntaxes.bin, themes.bin and acknowledgements.bin, and the second build embeds them, recompiling only the bat crate.

The tree’s environment makes git2 and onig_sys link the system libgit2 and oniguruma. build.sh checks the binary NEEDs both libraries, so a crate that falls back to compiling its bundled copy stops the build.

/usr/libexec/bat/man-pager strips the bold and underline that man writes as escape sequences and overstrikes, and hands the plain page to bat -l man -p, which highlights it. It is a script rather than a pipeline in MANPAGER because mandoc’s man splits MANPAGER on spaces and runs it with no shell. mandoc hands the pager one argument, the rendered page as a temp file (/tmp/man.XXXXXXXXXX), and sets no variable naming the page, so there is no page name to give bat --file-name; the script feeds bat the page on standard input, and the pager bat starts shows no file name. Without bat, /etc/bash.bashrc gives less a prompt of the position alone, for the same temp file.