[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] grep: -r with no args now searches "."
From: |
Jim Meyering |
Subject: |
Re: [PATCH] grep: -r with no args now searches "." |
Date: |
Mon, 02 Jan 2012 14:46:22 +0100 |
Paul Eggert wrote:
> This is a patch I've been meaning to write for years.
> Currently, one must write "grep -r PAT ." to search the working
> directory recursively, and that trailing " ." is an annoyance.
> When I added support for "grep -r", I forgot to have "grep -r PAT"
> search the working directory by default, instead of searching
> standard input (which makes no sense, even if stdin is a directory).
> This is not an upward compatible change, since "grep -r PAT <file"
> will no longer search standard input, but that's OK; nobody should
> be using "grep -r" that way anyway.
> * NEWS: Document this.
> * doc/grep.texi (File and Directory Selection, grep Programs, Usage):
> Likewise.
> * src/main.c (usage): Likewise.
> (grepdir): If DIR is null, search the working directory, but do
> not prepend "./" to the file names.
> (main): If recursing and no operands are given, search ".".
> * tests/Makefile.am (TESTS): Add r-dot.
> * tests/r-dot: New file.
> ---
> NEWS | 3 +++
> doc/grep.texi | 13 ++++++-------
> src/main.c | 48 +++++++++++++++++++++++++++++++++++-------------
> tests/Makefile.am | 1 +
> tests/r-dot | 14 ++++++++++++++
> 5 files changed, 59 insertions(+), 20 deletions(-)
> create mode 100755 tests/r-dot
That change looks fine, and fixes behavior that has annoyed me, too
for a long time. Here are some nit-picky wording suggestions:
> diff --git a/NEWS b/NEWS
> index d4475bc..e729e1b 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -35,6 +35,9 @@ GNU grep NEWS -*-
> outline -*-
>
> ** New features
>
> + If no file operands are given, grep -r now searches the working directory.
This sounds a little better:
If no file operand is given...
> + Formerly it ignored the -r and searched standard input nonrecursively.
> +
> grep now supports color highlighting of matches on MS-Windows.
>
> * Noteworthy changes in release 2.10 (2011-11-16) [stable]
> diff --git a/doc/grep.texi b/doc/grep.texi
> index 9889095..75980e0 100644
> --- a/doc/grep.texi
> +++ b/doc/grep.texi
> @@ -669,7 +669,7 @@ Search only files whose base name matches @var{glob}
> @opindex --recursive
> @cindex recursive search
> @cindex searching directory trees
> -For each directory mentioned on the command line,
> +For each directory operand,
> read and process all files in that directory, recursively.
> This is the same as the @samp{--directories=recurse} option.
>
> @@ -1010,10 +1010,12 @@ instead of strict equality with@ 2.
> @cindex variants of @command{gerp}
>
> @command{grep} searches the named input files
> -(or standard input if no files are named,
> -or the file name @file{-} is given)
> for lines containing a match to the given pattern.
> By default, @command{grep} prints the matching lines.
> +A file named @file{-} stands for standard input.
> +If no files are named, a recursive @command{grep}
How about this instead:
If no input is specified,
> +searches the working directory @file{.}, and a
> +nonrecursive @command{grep} searches standard input.
> There are four major variants of @command{grep},
> controlled by the following options.
...
> @@ -1509,8 +1522,9 @@ Context control:\n\
> \n"));
> fputs (_(after_options), stdout);
> printf (_("\
> -With no FILE, or when FILE is -, read standard input. If less than two
> FILEs\n\
> -are given, assume -h. Exit status is 0 if any line was selected, 1
> otherwise;\n\
> +When FILE is -, read standard input. With no FILE, read '.' if recursive,\n\
> +standard input if not. If fewer than two FILEs are given, assume -h.\n\
> +Exit status is 0 if any line was selected, 1 otherwise;\n\
I know this part of the text is legacy, but might as well adjust
while you move it...
s/was/is/
> if any error occurs and -q was not given, the exit status is 2.\n"));
...