[comp.sources.misc] v03i020: "redo"

goldman@cope.ucsf.edu (Eric S. Goldman) (05/18/88)

comp.sources.misc: Volume 3, Issue 20
Submitted-By: "Eric S. Goldman" <goldman@cope.ucsf.edu>
Archive-Name: redo

[This thing has a uuencoded shell script in it; the shell script contains
ESCAPE and CR (*not* NL) characters.  ++bsa]

[ If you think this is needed or worth (re-)posting, go ahead.  We have been
using it for years on several machines at UCSF.  (So why am I sending it now?
Well, some of the Korn shell discussions on the Net inspired me to send it,
since it appears that ksh [which I have never used] has a built-in "redo"
facility akin to the one below, and some csh users might want similar
capabilities.)  --ESG ]

-------------------------------------------------------------------------------
(The name of the author of the script below, which apparently was obtained from
Usenet years ago, has been lost.)

This script gives csh users the capability of command line editing by invoking
the open mode of ex on a file containing a history list, and then sourcing the
edited version of the desired command.

Since the script contains control characters (<CONTROL-M> and <ESC>), I have
provided a uuencoded version at the end.  The latter should be uudecoded and
used, *not* the clear-text version, which has had its control characters
changed to printable ones.

After uudecoding, to use "redo", do the following:

1) install it in /usr/local/bin/redo (or wherever else you'd like) with
   read-only-for-world permissions (i.e., do *not* make it executable);

2) do
	alias r /usr/local/bin/redo
   (or whatever, corresponding to where you installed it), and also put this
   alias in your favorite "dot" file;

3) type "r" to invoke it; use the "hjkl" keys to get to the line you want to
   edit; edit the line (remember that you're in the open mode of ex); and,
   when you're done, hit <CR> (*not* ZZ).

Enjoy.

--Eric Goldman
-----------------------------------------------------------
  Eric S. Goldman, M.D.
  Assistant Professor of Laboratory Medicine, Medicine, and
   Medical Information Science
  UCSF School of Medicine
  INET*: goldman@cope.ucsf.edu
  *(If you don't use a name server and don't have cope.ucsf.edu
   in your host table, please add "128.218.1.24     cope.ucsf.edu")
  UUCP: ...!ucbvax!ucsfcgl!cope.ucsf!goldman (MAY BE FLAKY!)
  BITNET: GOLDMAN@UCSFCOPE.BITNET

-----------------CLEAR-TEXT VERSION----DO *NOT* CUT AND USE--------------------
# Edit history list at line containing last command (open mode).
# Get up to 22 most recent commands.
# To work properly, put in .login:  alias r source /usr/local/bin/redo
# Author unknown.
history -h 22 >! /tmp/redo.$$

# Make CR map to :wq! and start ex quietly at 2nd to last line in open mode.
ex - '+map ^M :.wq\!^[|$-1 open' /tmp/redo.$$
tail -1 /tmp/redo.$$ >! /tmp/cmd.$$

# Insert into history without executing.
source -h /tmp/cmd.$$

# Clear out temporaries.
/bin/rm -f /tmp/{cmd,redo}.$$

# If thing chosen to redo is the redo alias itself then DON'T redo it.
if (!-2:0 != !!:0) !!

-----------------UUENCODED VERSION----CUT, UUDECODE, AND INSTALL---------------
begin 644 redo
M(R!%9&ET(&AI<W1O<GD@;&ES="!A="!L:6YE(&-O;G1A:6YI;F<@;&%S="!C
M;VUM86YD("AO<&5N(&UO9&4I+@HC($=E="!U<"!T;R R,B!M;W-T(')E8V5N
M="!C;VUM86YD<RX*(R!4;R!W;W)K('!R;W!E<FQY+"!P=70@:6X@+FQO9VEN
M.B @86QI87,@<B!S;W5R8V4@+W5S<B]L;V-A;"]B:6XO<F5D;PHC($%U=&AO
M<B!U;FMN;W=N+@IH:7-T;W)Y("UH(#(R(#XA("]T;7 O<F5D;RXD) H*(R!-
M86ME($-2(&UA<"!T;R Z=W$A(&%N9"!S=&%R="!E>"!Q=6EE=&QY(&%T(#)N
M9"!T;R!L87-T(&QI;F4@:6X@;W!E;B!M;V1E+@IE>" M("<K;6%P( T@.BYW
M<5PA&WPD+3$@;W!E;B<@+W1M<"]R961O+B0D"@IT86EL("TQ("]T;7 O<F5D
M;RXD)" ^(2 O=&UP+V-M9"XD) H*(R!);G-E<G0@:6YT;R!H:7-T;W)Y('=I
M=&AO=70@97AE8W5T:6YG+@IS;W5R8V4@+6@@+W1M<"]C;60N)"0*"B,@0VQE
M87(@;W5T('1E;7!O<F%R:65S+@HO8FEN+W)M("UF("]T;7 O>V-M9"QR961O
M?2XD) H*(R!)9B!T:&EN9R!C:&]S96X@=&\@<F5D;R!I<R!T:&4@<F5D;R!A
M;&EA<R!I='-E;&8@=&AE;B!$3TXG5"!R961O(&ET+@II9B H(2TR.C @(3T@
)(2$Z,"D@(2$*
 
end
-------------------------------------------------------------------------------