#!/bin/bash
if [ "" = "$1" ] || [ "--help" = "$1" ] || [ "-h" = "$1" ] ;then
   echo "Please give a filename to search for" >&2
   exit
elif [ ! -e "/var/db/pkg" ] ;then
   echo "Error: Not a Gentoo system!" >&2
   exit
fi
f="$1"
[ -e "$1" ]    &&f="$(realpath --no-symlinks $1)"
if   [ -d "$f" ] ;then f="^dir $f$"
elif [ -L "$f" ] ;then f="^sym $f "
elif [ -f "$f" ] ;then f="^obj $f "
fi
cd /var/db/pkg \
    &&grep --color=never -r --include=CONTENTS -e"${f}" \
    |sed -e's@/CONTENTS:... /@::/@' -e's@ .*$@@' -e's@^@=@'
