Wednesday, April 2, 2008

fmp

An outgrowth of my fpath script, I've written this. It's a script that does much of what ZSH's tab-completion does for manpages, but also provides the section numbers and full paths:

fmp

#!/usr/bin/perl -w
use strict;
use warnings;
use File::Basename;

scalar @ARGV || die "Usage: $0 [ --path ] expr\n";
my $path = 0;
my $expr = shift @ARGV;
(($expr, $path) = (shift @ARGV, 1)) if(scalar @ARGV && $expr eq '--path');

my @dirs = split(/:/, $ENV{MANPATH});
foreach(@dirs) {
foreach(/\s/ and <"$_"/*> or <$_/*>) {
my $sub = '1';
/man([0-9a-z]+)$/ and ($sub = $1);
print &manname($_) . "($sub)" . ($path and " @ '$_'" or '') . "\n" foreach(grep(/\/[^\/]*$expr[^\/]*$/, &getfiles($_)));
}
}

sub getfiles {
my $dir = shift;
return ($dir =~ /\s/ and <"$dir"/*> or <$dir/*>);
}
sub manname {
my $file = &basename(shift);
$file =~ s/\.(gz|bz2)$//;
$file =~ s/\.[0-9a-z]+$//;
return $file;
}
% perl fmp console
jconsole(1)
consoletype(1)
fgconsole(1)
gimp-console-2.4(1)
gimp-console(1)
console(4)
console_codes(4)
console_ioctl(4)
change_console(8)
showconsolefont(8)
console(n)
% perl fmp --path console
jconsole(1) @ '/etc/java-config-2/current-system-vm/man/man1/jconsole.1'
consoletype(1) @ '/usr/share/man/man1/consoletype.1.bz2'
fgconsole(1) @ '/usr/share/man/man1/fgconsole.1.bz2'
gimp-console-2.4(1) @ '/usr/share/man/man1/gimp-console-2.4.1'
gimp-console(1) @ '/usr/share/man/man1/gimp-console.1'
console(4) @ '/usr/share/man/man4/console.4.bz2'
console_codes(4) @ '/usr/share/man/man4/console_codes.4.bz2'
console_ioctl(4) @ '/usr/share/man/man4/console_ioctl.4.bz2'
change_console(8) @ '/usr/share/man/man8/change_console.8.bz2'
showconsolefont(8) @ '/usr/share/man/man8/showconsolefont.8.bz2'
console(n) @ '/usr/share/man/mann/console.n.bz2'
Post a Comment