I created the below script to put me in a given port's directory under /usr/ports and thought I'd share with the community. It's easy to use - just save the file with the name goport, chmod it to be executable, toss it somewhere in your PATH (I used /usr/local/sbin), and then type something like [cmd=]goport postfix[/cmd] and you'll be thrown into the /usr/ports/mail/postfix directory in a new shell. (The shell used is the one you're currently running.) This way, you can do what you need, then control-D out to where you were and continue with what you were doing.
It's not 100% because the whereis command is not 100% on the locating of specific ports, at least on 8.0. (Example: [cmd=]whereis unzip[/cmd] provides the paths executable files, but not /usr/ports/archivers/unzip. I know not why, but the ports it doesn't work on seem to be few and far between. The same command on 7.1 works perfectly, showing the executable paths and the /usr/ports/archivers/unzip hit.)
It's not 100% because the whereis command is not 100% on the locating of specific ports, at least on 8.0. (Example: [cmd=]whereis unzip[/cmd] provides the paths executable files, but not /usr/ports/archivers/unzip. I know not why, but the ports it doesn't work on seem to be few and far between. The same command on 7.1 works perfectly, showing the executable paths and the /usr/ports/archivers/unzip hit.)
Code:
#!/usr/bin/perl
###############################################################################
# #
# Perl script to spawn a shell in the port directory (under /usr/ports) of #
# the given port. #
# #
# Parameter 1: #
# Pass in the name of the port you wish to go to. #
# #
###############################################################################
# #
# Ruler's Common-Sense License: #
# #
# You may use this script however you want to, but I don't warrant it to #
# be good for anything in particular, though it happens to work well for #
# me. (I hate putting BS like this in, but I hate more being sued.) If #
# you use this script, you must keep this license and credit to me in it #
# in the form of this block, even if you modify it for your own use. If #
# you want to send me money for it, fantastic! Send me a private message #
# on the freebsd.org forums and I'll give you my PayPal address. :-) Even #
# just a simple 'thank you' would be nice. If not, that's fine too. All #
# hate mail/spam is sent directly to /dev/null #
# - Jim, AKA Ruler2112 #
# #
###############################################################################
# #
# History: #
# #
# 2010-01-20 by Ruler2112 Wrote initial version. #
# 2010-01-20 by Ruler2112 Released on freebsd.org forums. #
# #
###############################################################################
use strict;
my $portname = shift;
if($portname eq "")
{
print "You must specify a port name to go to.\n";
}
else
{
my ($workstr, $cutpos);
$workstr = `/usr/bin/whereis $portname`;
$cutpos = index($workstr, "/usr/ports/");
if($cutpos < 0)
{
print "Port $portname not found!!!\n";
}
else
{
my ($portloc);
$workstr = substr($workstr, $cutpos);
$cutpos = index($workstr, " ");
if($cutpos < 0)
{
$portloc = $workstr;
}
else
{
$portloc = substr($workstr, 0, $cutpos);
}
chomp($portloc);
print "Spawning shell at $portloc...\n";
print "Control-D or exit to return to your present directory.\n";
chdir($portloc);
exec $ENV{SHELL};
}
}
exit;