summaryrefslogtreecommitdiff
path: root/util/incfind.pl
blob: 85bf1f597ac52e56b1e69ff9724d5fbe315b3e0e (plain)
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
#!/usr/bin/perl

use warnings;
use strict;

die "Usage: $0 <searchterm>\n" if @ARGV != 1;
my $searchstr = shift @ARGV;

chdir "/usr/include" or die "Failed to change directory: $!\n";

my $cmd = "grep -RIlw $searchstr . | sort | uniq";

open(FH, '-|', $cmd) or die "Failed to pipe command: $!\n";
my @lines = <FH>;
close(FH);

if (@lines == 1) {
	$cmd = "vim +/$searchstr $lines[0]";
}
else {
	$cmd = "grep -RIHnw $searchstr . | less";
}

exec($cmd);
die "Failed to exec command: $!\n";