#!/usr/bin/perl -w
#
#NAME
#  grepath - list executables in the search path that match a pattern
#
#SYNOPSIS
#  grepath [pattern]
#
#DESCRIPTION
#  Run through the search path and list  all  the  executables  whose
#  paths match the pattern.
#
#  If no pattern is given, '.*' is used, so all executables are shown.
#
#  By "executable" we mean executable by the current uid/gid.  This is
#  what the perl -x operator tests for.
#
#OPTIONS
#
#EXAMPLES
#  To list all the exetables with 'play' anywhere in their name:
#     grepath play
#
#  To list all executables with two-char names:
#     grepath '/..$'
#
#  Long listing of all commands with 'play' in their names:
#     ls -li `grepath 'play'`
#  (Some fonts may confuse those two different "quotes".)
#
#FILES
#
#BUGS
#  A useful option would show only the first instance of each program.
#
#  The manual is longer than the program.
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu> 1997, 2002
#  Name changed from xpath to grepath to avoid conflict with OSX xpath command.

$| = 1;
$pat = shift || '.*';

@path = split(':',$ENV{'PATH'});
for $dir (@path) {
	@files = glob("$dir/*");
	for $file (@files) {
		print "$file\n"
			if (-f $file && -x $file && ($file =~ $pat));
	}
}
