I find myself looking for the location of a file and then executing some command on the result often. This short script automates the commonly used options.

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"; }

In reply to execute command on result of which/pmpath, etc. by Brovnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.