Skip to content
phieklPublic

About

Read-only terminal tool for comparing directory trees, git revisions and file archives side by side

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

binate

binate compares directory trees side by side in the terminal. Either side can be a directory on disk, a git revision, the git index or work tree, a tar or zip archive, a Linux initrd, a unified kernel image (UKI) or an EROFS image. It highlights differences in file contents and metadata and shows text changes line by line.

Open a subdirectory or nested archive as a comparison of its own, follow a file through its git history, or enable extraction to copy selected entries to disk.

Features

Parallel tree comparison

Both trees are scanned in parallel, and entries are paired by name. A mark between the two sides indicates differences in contents, mode, owner, mtime or type, or shows that an entry exists on only one side. You choose which differences matter, and -q compares by size and mtime instead of reading file contents.

Each entry is compared according to its type. Regular files are compared by their contents, symlinks by their targets, block and character devices by their major and minor numbers, and FIFOs and sockets by their type. Symlinks in the trees are never followed, and special files in them are never opened.

binate comparing two directory trees with a preview of changes to
sshd_config and file metadata

Panels under each side show the selected entry's details and highlight differences. A preview shows the first differences between the selected files before you open the diff view.

File diffing

Enter opens two text files side by side, with word-level highlights inside changed lines.

Side-by-side diff of sshd_config with changed words and added or
removed lines highlighted

Navigation and search

Jump between differences, hide identical entries, or filter and search entry names using regular expressions or literal text. Filtering covers the whole tree.

binate filtering both directory trees to Stockholm, highlighting a
file type difference

Native git object reader

Use -g, or run binate as agitate, to compare two revisions or trees within them. Data is read directly from the repository without running git or checking anything out. Files are compared by their object IDs without reading their contents. Two revisions of Linux compare in about 0.2 seconds.

Give . on either side to compare a revision with the work tree on disk. The right side defaults to the work tree, and the left defaults to HEAD. binate starts at the repository's top and includes tracked files and untracked files that git's ignore rules allow. Each of them shows its status, as git status --short does, with A, M, D and ?? telling what is staged, what isn't and what is untracked.

Give : for the index, which holds what is staged. agitate --cached compares HEAD with the index, as git diff --cached does, and agitate : compares the index with the work tree, as git diff does.

The panels on both sides show the commit that last changed each entry. From the action menu, a, you can show that commit's message or a summary of the files it changed, or open the trees from before and after it side by side to see exactly what it changed. There, the panels again show each entry's last commit. Repeating this follows a file back through its history, one change at a time. Esc goes back a step.

binate comparing Linux git revisions with a file diff preview and each
file's last commit details

Archives, initrds and images

Use tar:archive or zip:archive on either side to compare an archive with a directory, a git revision or another archive. Tar archives can be uncompressed or compressed with gzip, bzip2, xz, lzma, zstd or lz4. Use cpio:initrd to compare an initrd as Linux unpacks it at boot. binate supports uncompressed cpio archives and the compression formats Linux supports for initrds. Use cpio:initrd@1 to show only the second archive. Use uki:image.efi to compare a unified kernel image by its stub and sections, with initrds left packed for o to open. Use erofs:system.img to compare an EROFS image as Linux mounts it, compressed or not. Use a pipe or process substitution to compare a tree from another host or a container without first saving the archive to a file.

binate keeps the archived file contents in an unnamed temporary file in TMPDIR (default /tmp) and uses the metadata the archive records. Run binate as imaginate to detect archive formats automatically and omit the prefixes.

Append :path to an archive argument to compare a directory inside it, as in tar:app-1.0.tar.gz:app-1.0. The path can also name a nested archive.

Press o on a directory or an archive to open it as a comparison of its own, on either side or both, and Esc to go back. An archive inside an archive opens the same way, and a release tarball's versioned top directory can be compared with the other release's directly.

Give --extract-dir or set BINATE_EXTRACT_DIR to enable extraction. Press x in the tree or choose Extract from the Actions popup (a) to copy entries from an archive, a git revision or a directory. Each session writes its output to its own subdirectory, under a directory named for the two sides.

Read-only, escaped output and Landlock sandbox

binate never changes files itself, except to extract entries into a directory you name. Press e to open a file in your editor. Control characters, bidi overrides and invisible characters in names and contents are shown escaped, never sent to the terminal. Landlock prevents the process that reads files from writing files elsewhere or running programs, and restricts network access. With -g, it also prevents reads outside the repository. A seccomp filter keeps that process from typing into the terminal as if from the keyboard, which Landlock doesn't cover.

Editor and terminal integration

binate opens your $VISUAL or $EDITOR, and follows the terminal's palette, with colours changed through BINATE_COLORS or turned off with NO_COLOR.

Examples

Compare two directory trees:

$ binate ~/src/old ~/src/new

Check a backup against the originals quickly, by size and modification time instead of contents:

$ binate -q /mnt/backup ~/photos

Show everything in a directory as added, by comparing it with nothing:

$ binate /dev/null ~/project

Compare two branches of the git repository you're in:

$ binate -g main feature

Compare HEAD with the work tree, from anywhere in the repository:

$ binate -g

Give one revision to compare it with the work tree, as in agitate main.

Compare the tag v1.0 with HEAD in the repository at ~/src/project:

$ binate -g -C ~/src/project v1.0 HEAD

When invoked as agitate, binate needs no -g. Compare HEAD~3 with HEAD:

$ agitate HEAD~3 HEAD

Compare main of another repository with the work tree of the one you're in, or the HEAD of two other repositories:

$ agitate ~/src/fork@main
$ agitate ~/src/a@ ~/src/b@

Without -g, a git: side compares a revision with any directory:

$ binate git:~/src/project@v1.0 /mnt/project

Compare a release archive with its source tree or compare a remote host's /etc with your local copy:

$ binate tar:app-1.0.tar.gz ~/src/app
$ binate zip:app-1.0.zip ~/src/app
$ binate tar:<(ssh host tar -C /etc -c .) /etc

Compare the initrds of two kernels:

$ binate cpio:/boot/initrd.img-6.1 cpio:/boot/initrd.img-6.6

Compare the stubs, command lines and other sections of two unified kernel images:

$ binate uki:/boot/efi/EFI/Linux/old.efi uki:/boot/efi/EFI/Linux/new.efi

Compare two EROFS images, as of two releases of a system:

$ binate erofs:system-1.0.erofs erofs:system-1.1.erofs

Compare a tarball and a zip archive with automatic format detection:

$ imaginate app-1.0.tar.gz app-1.1.zip

Compare two releases by selecting the versioned directory in each tarball:

$ imaginate app-1.0.tar.gz:app-1.0 app-1.1.tar.gz:app-1.1

Press ? to list the current screen's key bindings, or run binate --help to list command-line options. binate(1) summarises both, and the manual describes everything in detail.

Requirements

binate requires Linux with /proc mounted, and a terminal. Sandbox protection depends on the kernel, and network restrictions are partial. Without Landlock, binate runs unprotected. -v reports the Landlock ABI in effect; see the manual for the restrictions each ABI provides.

Building and testing

make            # build/binate and its build/agitate and build/imaginate links
make test       # unit and end-to-end tests
make vet        # go vet
make man        # the man pages in build/man/, requires go-md2man
make fuzz       # all fuzz targets, FUZZTIME=10s by default
staticcheck ./...

The build targets x86-64-v3 CPUs (roughly 2013 and later) by default. make GOAMD64=v1 can be used for older CPUs. binate needs a 64-bit platform, as x86-64 or arm64, and a 32-bit build stops with an error saying so. Install agitate and imaginate as symlinks to binate, as in the build directory. Use agitate to compare git revisions without -g and imaginate to compare archives without cpio:, erofs:, tar:, uki: or zip:.

make man builds binate(1) from doc/binate.1.md and binate-manual(7) from doc/manual.md. It links the corresponding agitate and imaginate man pages to them. Install go-md2man with your package manager or run go install github.com/cpuguy83/go-md2man/v2@v2.0.7. Read the results with man -l build/man/binate.1 and man -l build/man/binate-manual.7. A page's footer date defaults to the last commit date of its Markdown source. Set MAN_DATE=YYYY-MM-DD when building without git metadata.

binate has no TUI library: the terminal layer is written on golang.org/x/term and golang.org/x/sys. go-landlock provides the sandbox. For archive decompression, binate uses ulikunitz/xz for xz and lzma, klauspost/compress for zstd, pierrec/lz4 for lz4 and Go's standard library for deflate, gzip and bzip2. binate uses pxy.se/go/initrd to read initrds, including archives compressed with lzo, pxy.se/go/uki to read UKIs and pxy.se/go/erofs to read EROFS images. The line diff is Go's internal/diff, changed to return line operations (BSD-3-Clause, see LICENSES).

See doc/CONTRIBUTING.md for conventions and doc/testing.md for what the tests cover.

Acknowledgements

Inspired by duodiff, a similar tool that allows merging and synchronization of files and directories, while binate focuses on sandboxed read-only comparison.

About

Read-only terminal tool for comparing directory trees, git revisions and file archives side by side

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages