diff options
author | John Ankarström <john@ankarstrom.se> | 2021-06-15 07:46:56 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-06-15 07:46:56 +0200 |
commit | 21be8e78d7a629f57f28620dc4445bc230818ef4 (patch) | |
tree | 98809b4cf87e2bc2d09b5f88aed8464aea915875 | |
parent | 5f09e6cbdc167a84f2edf3a402ce1e09c234d34c (diff) | |
download | xutil-21be8e78d7a629f57f28620dc4445bc230818ef4.tar.gz |
Improve 'g' utility
-rwxr-xr-x | g | 29 |
1 files changed, 26 insertions, 3 deletions
@@ -1,5 +1,28 @@ #!/bin/sh -p grep -n "$*" $( - find . -name '*.c' -or -name '*.h' -or -name '*.cc' | - sed s,./,,) +IFS=' +' + +pat= +opt= +i=0 + +while [ $((i++)) -lt $# ]; do + case "$1" in + -*) opt=`printf '%s%s\n' "$opt" $1` + shift ;; + *) break ;; + esac +done + +[ $# -eq 0 ] && { echo usage: $0 [-...] pattern [file ...] 1>&2; exit 1; } + +pat=$1 +shift + +files=`find . -name '*.c' -or -name '*.h' -or -name '*.cc' | sed s,./,,` +[ -z "$files" ] && [ -z "$*" ] && { echo no matching files found 1>&2; exit 1; } + +# todo (?): treat argument \*.x like -or -name \*.x + +p grep $opt -n "$pat" $files "$@" |