Description: Don’t print file name if only one file is grepped This patch makes zutils behave like grep(1) in that the default for grep_show_name is false when one file is being searched and true when multiple files are being searched. Of course, -h and -H overwrite the default. Author: Michael Stapelberg Bug-Debian: http://bugs.debian.org/694024 Forwarded: Last-Update: 2012-12-04 --- zutils-0.9.orig/main.cc +++ zutils-0.9/main.cc @@ -245,6 +245,7 @@ int main( const int argc, const char * c int argind = 0; bool grep_list = false; bool grep_show_name = true; + bool grep_show_name_default = true; bool grep_pattern_found = false; for( ; argind < parser.arguments(); ++argind ) { @@ -302,8 +303,8 @@ int main( const int argc, const char * c case 'f': grep_args.push_back( "-f" ); grep_args.push_back( arg ); grep_pattern_found = true; break; case 'F': grep_args.push_back( "-F" ); break; - case 'h': grep_show_name = false; break; - case 'H': grep_show_name = true; break; + case 'h': grep_show_name = false; grep_show_name_default = false; break; + case 'H': grep_show_name = true; grep_show_name_default = false; break; case 'i': grep_args.push_back( "-i" ); break; case 'I': grep_args.push_back( "-I" ); break; case 'l': grep_args.push_back( "-l" ); grep_list = true; break; @@ -350,6 +351,11 @@ int main( const int argc, const char * c if( filenames.empty() ) filenames.push_back("-"); + if( grep_show_name_default && filenames.size() == 1 ) + { + grep_show_name = false; + } + int retval = ( ( program_mode == m_zgrep ) ? 1 : 0 ); while( !filenames.empty() ) {