#!/bin/sh
# ggf, stands for Git Grep
# find a file and line number
# requires pick(1) to be installed

query="$1"
flag="-n"
if test "$1" = "-n"; then
  flag=""
  query="$2"
fi
if test "$1" = "+"; then
  query="$2"
fi

full=`git grep $flag $query | pick`
file=`echo "$full" | cut -d : -f 1-2`
if test "$1" = "+"; then
  echo $file | sed -e "s/:/ +/g"
else
  echo "$file"
fi
