#!/bin/bash log="@GENTOO_PORTAGE_EPREFIX@/var/tmp/portage/*/*/temp/build.log" cmd="tailf" c=0 die() { echo -e "$*" >&2; exit 1; } if [[ $(echo $log) = "$log" ]]; then echo "No running build found" exit 0 elif [[ ! $1 ]]; then echo "Running builds - use '${0##*/} NUMBER' to select" for i in $log; do [[ $i =~ ^${log%%\**}([^/]*)/([^/]*)${log##*\*}$ ]] || continue echo -e "$((++c))\t${BASH_REMATCH[2]}\t(${BASH_REMATCH[1]})" done else [[ -z ${1//[0-9]} && $1 -gt 0 ]] || die "Argument should be a number greater 0" for i in $log; do [[ $i =~ ^${log%%\**}([^/]*)/([^/]*)${log##*\*}$ ]] || continue [[ $((++c)) -eq $((10#$1)) ]] || continue [[ -f ${i} ]] || die "Build number $1 was gone in the meanwhile" echo -ne "\033]0;Viewing: ${BASH_REMATCH[2]}\t(${BASH_REMATCH[1]})\007" exec $cmd $i done die "Build number $1 not found (there are only $((c--)) build(s) running)" fi