grep.zsh 578 B

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