fgt 521 B

12345678910111213141516171819202122232425
  1. #!/bin/sh
  2. # fgt, stands for Find Grep Type
  3. # find a file and line number but type the query inside of pick(1)
  4. # CAVEAT: Loading grep each time is slow. If you use a faster grep
  5. # it may be faster!
  6. # requires pick(1) to be installed
  7. query="$1"
  8. flag="-n"
  9. if test "$1" = "-n"; then
  10. flag=""
  11. query="$2"
  12. fi
  13. if test "$1" = "+"; then
  14. query="$2"
  15. fi
  16. full=`find . -type f -exec grep $flag "" {} + | pick`
  17. file=`echo "$full" | cut -d : -f 1-2`
  18. if test "$1" = "+"; then
  19. echo $file | sed -e "s/:/ +/g"
  20. else
  21. echo "$file"
  22. fi