dotfiles/.bash_rc.d/10.grep.sh

24 lines
514 B
Bash
Raw Normal View History

2019-10-20 16:24:07 -05:00
# print all the todos in the files in this directory
todos() {
dgrep TODO $*
}
# print all the notes in the files in this directory
notes() {
dgrep NOTE $*
}
# run a grep on all files in a directory
dgrep() {
# if no directory or file was given then use pwd
dir=${2:-$(pwd)}
# we require a pattern
if [[ -z "$1" ]]; then
echo "Must pass in a pattern" 1>&2
return 1
fi
# now we can execute
grep -n -H -I -R $1 $dir | awk -F'[ \t]*(//|#|;) ' '{print $1 "\t" $2}'
}