gsrc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/ksh
  2. #
  3. # GSRC = Grep SouRCe
  4. #
  5. # Grep files, but only those in a project define by a TM5 rc file.
  6. #
  7. # ARGUMENT : Regular Expression and options for Egrep
  8. # --------
  9. #
  10. # OPTION
  11. # ------
  12. #
  13. # -r RCFILE : rc file (default is $RCFILE in settings, if defined, or the
  14. # most recent)
  15. #
  16. #
  17. # SETTING : specify your TM5 dir and default rc file in the SETTINGS
  18. # --------- section
  19. #
  20. #
  21. # EXAMPLES
  22. # ---------
  23. #
  24. # gsrc -in "module dep"
  25. #
  26. #
  27. # LIMITATIONS
  28. # -----------
  29. # Works only with pycasso rcfiles.
  30. # A bit slow for repetitive search. See README in this dir for faster ways.
  31. #
  32. # 3 Jan 2011 - P. Le Sager - v0
  33. #
  34. ########################################################
  35. USAGE="\
  36. Grep SouRCe : look for PATTERN in TM5 source dirs.
  37. usage: ${0##*/} PATTERN
  38. "
  39. #----------------
  40. # SETTINGS
  41. #----------------
  42. # TM5 dir
  43. TM=$HOME/TM5MP
  44. # default RC file
  45. rcfile='base/trunk/rc/pycasso-tm5_chembase.rc'
  46. cd $TM
  47. # -----------------------------------------
  48. # Arguments
  49. # -----------------------------------------
  50. while getopts :r: OPT; do
  51. case $OPT in
  52. r) rcfile=$OPTARG
  53. ;;
  54. *) print "$USAGE"
  55. exit 2
  56. esac
  57. done
  58. shift $(( OPTIND - 1 ))
  59. # At least one argument
  60. [ $# -eq 0 ] && print "$USAGE" && exit 1
  61. # Use the most recent rc file if default does not exist
  62. [[ -f $rcfile ]] || rcfile=$(ls -1trL *.rc | tail -1)
  63. # list of files
  64. file=$(${0%/*}/get_tmflist -d $TM "$rcfile")
  65. egrep "$@" $file
  66. exit