fsrc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/ksh
  2. #
  3. # FSRC = Find SouRCe
  4. #
  5. # Find file. Limit search to a project directory tree, and apply
  6. # precedence rule (i.e. ignore files that are overwritten with another
  7. # file in the project). In doing so, stops in the first directory with
  8. # one or more matching file(s).
  9. #
  10. #
  11. # ARGUMENT
  12. # --------
  13. # File name. Patterns matching (a/k/a globbing), and word splitting are
  14. # ON.
  15. #
  16. # OPTIONS
  17. # --------
  18. #
  19. # -r RCFILE : rc file (default is $rcfile, if defined, or the
  20. # most recent. See SETTING section.)
  21. #
  22. # -e|c|v|l : to edit found file(s) with emacs|emacsclient|less|vi
  23. #
  24. #
  25. # SETTING : specify your TM5 dir and default rc file in SETTINGS
  26. # --------- section in the script.
  27. #
  28. #
  29. # EXAMPLES
  30. # ---------
  31. #
  32. # To find & list files : fsrc "*chem*"
  33. #
  34. # To find & edit files : fsrc -c "emission.F90"
  35. #
  36. #
  37. # 3 Jan 2011 - P. Le Sager - v0
  38. #
  39. ########################################################
  40. #set -x
  41. USAGE="\
  42. Find SouRCe : look for FILE in TM5 source dirs.
  43. usage: ${0##*/} [-r RCFILE] FILE_PATTERN
  44. "
  45. #----------------
  46. # SETTINGS
  47. #----------------
  48. # TM5 dir
  49. TM=$HOME/TM5MP
  50. # default RC file
  51. rcfile='pycasso-tm5_chembase.rc'
  52. cd $TM
  53. # ------------------------------
  54. # default command and options
  55. # ------------------------------
  56. while getopts :r: OPT; do
  57. case $OPT in
  58. r) rcfile=$OPTARG
  59. ;;
  60. *) print "$USAGE"
  61. exit 2
  62. esac
  63. done
  64. shift $(( OPTIND - 1 ))
  65. # At least one argument
  66. [ $# -eq 0 ] && print "$USAGE" && exit 1
  67. # Use the most recent rc file if not passed and no default
  68. [[ -f $rcfile ]] || rcfile=$(ls -tL *.rc)
  69. # list of files
  70. file=$(${0%/*}/get_tmflist -d $TM "$rcfile")
  71. find $file -name "$@"
  72. exit