#!/bin/bash
# +SPDX:MIT
# A dumb portage build log viewer
# Currently relies on logging being done in a specific way.
# all arguments are sent to bat

## WE NEED SOME DEPENDENCIES
depcheck() {
	if ! command -v "$1" &> /dev/null ; then
		echo "Missing dependency $1"
		exit 1
	fi
}
depcheck fzf
depcheck bat
depcheck xargs

# in true unix style this is just a long pipe of pipes
# shellcheck disable=2068
find /var/log/portage/build -type f -iname "*.log" | sed -e 's|/var/log/portage/build/||' -e 's/:.*//' | sort | uniq | fzf | xargs --no-run-if-empty --replace={} find /var/log/portage/build -iwholename "*{}*" | sort | xargs bat ${@}
