grep.zsh 645 B

12345678910111213141516171819202122232425262728
  1. # is x grep argument available?
  2. grep-flag-available() {
  3. echo | grep $1 "" >/dev/null 2>&1
  4. }
  5. GREP_OPTIONS=""
  6. # color grep results
  7. if grep-flag-available --color=auto; then
  8. GREP_OPTIONS+=" --color=auto"
  9. fi
  10. # ignore VCS folders (if the necessary grep flags are available)
  11. VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
  12. if grep-flag-available --exclude-dir=.cvs; then
  13. GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
  14. elif grep-flag-available --exclude=.cvs; then
  15. GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
  16. fi
  17. # export grep settings
  18. alias grep="grep $GREP_OPTIONS"
  19. # clean up
  20. unset GREP_OPTIONS
  21. unset VCS_FOLDERS
  22. unfunction grep-flag-available