-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathf
executable file
·52 lines (40 loc) · 891 Bytes
/
f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
use strict;
use Term::ReadKey;
sub usage {
print <<EOF;
f something
f something files
EOF
exit;
}
if ($#ARGV eq -1){
usage();
}
my @files;
my @grep;
while (my $arg = pop @ARGV){
if (-d $arg || -e $arg){
push @files, $arg;
} else {
push @grep, $arg;
}
}
my $files = join(' ', @files);
if (!$files){
$files = '*';
}
my $grep = join(' ', reverse @grep);
my $cmd = "grep";
$cmd .= " --color=always";
$cmd .= " -r"; # recursive
$cmd .= " -n"; # show line numbers
$cmd .= " -F"; # = fixed string (ie not regex)
$cmd .= " -C9"; # 3 lines of context
$cmd .= " -- "; # We do this with -- mode so we can search for > < - etc
$cmd .= " '$grep'";
$cmd .= " $files";
$cmd .= " | cut -c1-250"; # Just ignore matches in compiled css etc
$cmd .= " | less -R"; # -R = retain control chars (ie colors)
# print "$cmd\n";
system($cmd);