Executes some sort of find command specified in %find to locate a file
then executes a command on the result of that find.
e.g.
1> pmpath Text::Balanced /usr/local/lib/perl5/site_perl/5.6.1/Text/Balanced.pm 2> vi /usr/local/lib/perl5/site_perl/5.6.1/Text/Balanced.pm
(or alternatively)
1> vi `pmpath Text::Balanced`
becomes 1> pvi Text::Balanced
#! /usr/local/bin/perl -w # # $Id: wvi,v 1.1 2001/05/22 09:24:06 richard Exp richard $ # # use to execute command on output of which, etc. # # RAN 14-May-01 original # Copyright (C) Richard Nuttall richard@nuttall.uk.net All rights res +erved. # You may use this and change it so long as the copyright message stay +s # # DESCRIPTION : # # Executes some sort of find command specified in %find to locate a fi +le # then executes a command on the result of that find. # e.g. # 1> pmpath Text::Balanced # /usr/local/lib/perl5/site_perl/5.6.1/Text/Balanced.pm # 2> vi /usr/local/lib/perl5/site_perl/5.6.1/Text/Balanced.pm # # (or alternatively) # 1> vi `pmpath Text::Balanced` # # becomes # # 1> pvi Text::Balanced # install this as e.g. wvi, then link other files to it. # e.g. # # 1> ln -s wvi wless # 2> ln -s wvi wls # 3> ln -s wvi pwvi # # Add other lines into wvi to broaden the range of choices as needed. # The pm utils are available from http://language.perl.com/misc/pmtool +s-1.00.tar.gz, # including pmpath. use strict; my $arg = shift; my $whatami = $0; my %whatdoido = (); my %find = (); my $base = "/usr/local/perl/"; # directory where these are installed # To add other operations, add a line here. $find{$base . "wvi"} = "which"; $find{$base . "wf"} = "which"; $find{$base . "wless"} = "which"; $find{$base . "wls"} = "which"; $find{$base . "pvi"} = "/usr/local/bin/pmpath"; $find{$base . "pless"} = "/usr/local/bin/pmpath"; my $found = $find{$whatami} || die "Don't know what to do with [$whata +mi]\n"; my $which = `$found $arg`; $whatdoido{$base . "wvi"} = "/usr/bin/vi"; $whatdoido{$base . "wf"} = "/usr/bin/file"; $whatdoido{$base . "wless"} = "/usr/bin/less"; $whatdoido{$base . "wls"} = "/usr/bin/ls -al"; $whatdoido{$base . "pvi"} = "/usr/bin/vi"; $whatdoido{$base . "pless"} = "/usr/bin/less"; chop $which; if ($which =~ /^\//) { die "Don't know what to do with [$whatami]\n" unless $whatdoido{$wh +atami}; exec("$whatdoido{$whatami} $which"); } else { print "$which\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: execute command on result of which/pmpath, etc.
by John M. Dlugosz (Monsignor) on Jun 22, 2001 at 20:23 UTC |