#!/bin/sh

set -x


if test -z "$(groups | grep -o portage)" && test ! "$(id -u)" = "0"
then
    echo 'Comp: Not in Portage group'
    exit 1
fi

genlop -cn \
    | tr -d '\n' \
    | sed -e 's/.*\* //' \
	  -e 's/current merge time/CMT/' \
	  -e 's/ hours\?, /:/g' \
	  -e 's/ hours\? and /:/g' \
	  -e 's/ minutes\? and /:/g' \
	  -e 's/ seconds\?//g' \
	  -e 's/:\([1-9]\)\./:0\1./g' \
	  -e 's/:\([1-9]\):/:0\1:/g' \
	  -e 's/ \([1-9]\):/ 0\1:/g' \
	  -e 's/!!! Error: no working merge found.*/No working merge found./' \
    | xargs echo Comp:
