1#!
2#[[BEGIN PROPERTIES]]
3# Type = Command
4# Order = 53.0
5# Interpreter = perl
6# Caption = grep
7# Descr =Search with a text pattern in files and directories
8# Descr =recursively, and show the matching lines. The text
9# Descr =pattern is asked. The search is case-sensitive.
10# Descr =
11# Descr =Selection details:
12# Descr =
13# Descr =  Source: Ignored.
14# Descr =
15# Descr =  Target: Files and directories to be searched.
16# Icon = grep.tga
17#[[END PROPERTIES]]
18
19use strict;
20use warnings;
21BEGIN { require "$ENV{'EM_DIR'}/res/emFileMan/scripts/cmd-util.pl"; }
22
23if (IsFirstPass()) {
24
25	ErrorIfNoTargets();
26
27	my $pat=Edit(
28		"grep",
29		"Please enter the text pattern for the search. It's\n".
30		"a regular expression (see grep(1) for details).",
31		""
32	);
33
34	SetFirstPassResult($pat);
35
36	SecondPassInTerminal("grep");
37}
38
39my $pat=GetFirstPassResult();
40
41my $e=TermRun('grep','-r','-n','-e',$pat,GetTgt());
42
43if ($e==256) {
44	print("\nNo match found.\n");
45	$e=0;
46}
47
48TermEndByUser($e);
49