/
mff
executable file
·55 lines (47 loc) · 986 Bytes
/
mff
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
52
53
54
55
#!/usr/bin/perl -w
#
# mff: my file find
#
# Convenient locate+grep sequence wrapper to find files easily
#
# Saves the effort of having to type combos like:
#
# locate [options] some_str | grep [options] another_str ...
#
# Supports multiple arguments in sequence.
#
# args that are have no upper-case are considered case insensitive
#
# Supports full PCREs, not just plain-strings
# (Doesn't force user to specifiy options to interpret as regex)
#
sub no_uppercase_arg($) {
my $arg = shift;
return ($arg !~ /[A-Z]/);
}
#
# pipeline_arg($arg)
# map argument to a pipeline argument
#
sub pipeline_arg($) {
my $arg = shift;
my $to_add;
if (no_uppercase_arg($arg)) {
$to_add = '|grep -Pi';
} else {
$to_add = '|grep -P';
}
$to_add .= " '$arg'";
$to_add;
}
sub argv_to_pipeline(@) {
my $cmd = "locate ''";
for (@_) {
$cmd .= pipeline_arg($_);
}
$cmd;
}
#
# --- main
#
system(argv_to_pipeline(@ARGV));