Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Private Utilities

by Intrepid (Deacon)
on Dec 01, 2005 at 08:29 UTC ( #513214=note: print w/ replies, xml ) Need Help??


in reply to Private Utilities

<UPDATE> prompted by a reaction in the chatterbox

If you get upset by things like seeing the company name "Microsoft" rendered in various creative / implicitly critical ways, please stop reading now; I don't want to inadvertantly help you even to a tiny degree with this code! Making even one of your days a tiny bit easier might distract you from the important recognition that you've got far worse problems than doskey macros to deal with (problems of an cognitive sort), and it would thus be uncompassionate of me. Shoo.

</UPDATE>

I was just looking at how impoverished* my Windo$e CMD.exe prompt seemed (I go months without using one, but building Perl under Win32(native) a little while ago made me get re-acquainted with it). I decided to pull together a few doskey macros that could be loaded into a CMD session at any point (by running a batch *.cmd file). Here they are.

* compared with my Cygwin shell

@ECHO OFF rem ark * We have to get perl into our path so this tries to make sur +e rem * that it will be. Tested *only* on Windows XP. Most users mi +ght rem * just as well remove this if they are sure Perl is always in + PATH. @PATH | findstr /R /I /O "perl[^\\]*\\bin" >NUL @if ERRORLEVEL 1 ( REM EMBER TO adjust this for the path to perl.EXE on your system. set PATH=c:\ADDITI~1\win32perl\bin;%PATH% ) rem desc * a better dir command that outputs what we expect such a com +mand rem * to do, w/o the leading and trailing junk. doskey udir=perl -le "$ad=pop(@ARGV);$ad=q[.] unless $ad;@zult=(grep{$ +_ and not /\A\s/}grep[chomp],`cmd /c dir $ad /N/Q/TW`);for((grep subs +tr($_,24,5) eq q[<DIR>],@zult),(grep substr($_,24,5) ne q[<DIR>],@zul +t)){s{\s\s[[:upper:]]+\\}{};print}" $* doskey uloc=perl -MFile::Find=find -MEnv=@PATH -wle "$ARGV[0]=qw[ $* ] +;die q[An argument is required! Aborting.] unless $ARGV[0];print qq/L +ooking for $ARGV[0]/;@lf=$ARGV[0];push @lf,qq|$ARGV[0].exe| unless $A +RGV[0]=~/\.exe$/i; find(sub{$ef=$_;return unless grep{$ef eq $_ or /\ +A\Q$ef\E\z/i}@lf;$ff=$File::Find::name;$ff=~y:/:\\:;print $ff and exi +t 0},@PATH); print q[None found.]" doskey pmquery=perl -le "do{$modn=$_;s!::!/!g;$_.=q[.pm];print qq[$mod +n is not installed.\n] and next if !(eval{require \"$_\";1} and !$@); +$modv=defined(${$modn.q[::VERSION]}) ?${$modn.q[::VERSION]}:q{[versio +n undefined]};$numtyp=(2>$modv=~tr/.//) ?'%%s':'%% 6d';printf qq[ %% +-*s $numtyp in %%s\n],(length>30 ? 5+length:15+length),$modn,$modv,$I +NC{$_}}for @ARGV;" $* doskey perlv=perl -le "printf qq[%%vd$/]=> $^V" doskey checkpath=perl -MEnv=@PATH -le "print for map {-d $_ ? lcfirst( +$_):qq[$_ ** DOES NOT EXIST **]}@PATH" doskey checkperlinc=perl -le "print for map {-d $_ ? lcfirst($_):qq[$_ + ** DOES NOT EXIST **]}@INC" doskey checktempdirs=perl -e "print for map {sprintf(q[%%-6s is %%s].q +q[\n], $_, ($ENV{$_} || 'not defined in env'))}qw(TEMP TMP TMPDIR)"

  • pmquery tells us the location and (if applicable) version of an installed Perl module. Quite useful.
  • perlv simply prints the familiar (new 'v-string' style) Perl version.
  • checkpath pretty-prints the elements in PATH, one per line.
  • checkperlinc pretty-prints the elements in Perl's @INC, one per line.
  • checktempdirs shows what each of the commonly looked-at temporary file locations is defined to, or shows if it is not.
  • uloc and udir are my experiments with reimplementing the `which' and `dir' commands. uloc in particular is not truly reliable.

Note that as Windo$e CMD shell has no concept of "continuing a single command over multiple lines by escaping the line-endings (with "\"), these doskey definitions must be single lines, no matter how they end up looking on your screen (in a browser or editor). Cleaning them up is the reader's responsibility.


Comment on Re: Private Utilities
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://513214]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2014-09-17 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (72 votes), past polls