#!/bin/bash # # Syntax: tgrep [-h] [-l] [-p] [-w] [-u] [-o] string # # Purpose: Searches all .tex files in the directory ~ and its # subdirectories for string . # If the option -w is specified, tgrep searches for string as a # word. # If the option -u is specified, tgrep distinguishes between upper # and lower case letters. # If the option -p is specified, the search considers only the # directory ~/pub . # If the option -l is specified, the search considers only the # directories ~/pub, ~/edu, and ~/latex . # If the option -o is specified, 'old' and 'bak' subdirectories are # also searched. # The -h flag shows the help info for this command. # Created: Nov 8, 1993 by Bart De Schutter # Last revised: Jan 2, 2011 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: latex if [ $# -ge 1 -a "$1" = "-h" ]; then sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi # # Process input arguments and display error message if necessary. # word_option="" case_option="-i" old_dirs=0 pub_dir_only=0 latex_dirs_only=0 while getopts :wpulo option do case "$option" in w) word_option="-w";; u) case_option="";; l) latex_dirs_only=1;; p) pub_dir_only=1;; o) old_dirs=1;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done shift $(($OPTIND-1)) if [ $# -ne 1 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires exactly 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi if [ $old_dirs -eq 0 ]; then find_options='! -path "*/old/*" ! -path "*/bak/*"' else find_options="" fi cd ~ if [ $latex_dirs_only -eq 1 ]; then search_dirs="./pub ./edu ./latex" else if [ $pub_dir_only -eq 1 ]; then search_dirs="./pub" else search_dirs="." fi fi find $search_dirs $find_options\ -name "*.tex" \ -exec findgrepsub $case_option $word_option "$1" {} \;