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

hartley@uvm-gen.UUCP (Stephen J. Hartley) (05/21/88)

From article <8805171730.AA22099@cope>, by goldman@cope.ucsf.edu (Eric S. Goldman):
< comp.sources.misc: Volume 3, Issue 20
< Submitted-By: "Eric S. Goldman" <goldman@cope.ucsf.edu>
< Archive-Name: redo
< 
< -----------------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) !!
< 

I tried this and noticed that commands "redone" this way do not go
through csh aliasing, i.e. if you have "mv" aliased to "mv -i" and
then "redo" some previous command that had a "mv" in it, then you will
have a plain "mv" redone and run the risk of clobbering a file.
Does anybody know why the aliasing check is bypassed?
-- 
Stephen J. Hartley, Dept Comp Sci Elec Eng, Univ Vermont, Burlington, VT  05405
CSNET:	hartley@uvm.EDU					(802) 656-3330, 862-5323
USENET:	...!uunet!uvm-gen!hartley, {decvax,ihnp4,linus}!dartvax!uvm-gen!hartley

mkhaw@teknowledge-vaxc.ARPA (Mike Khaw) (05/25/88)

In article <853@uvm-gen.UUCP> hartley@uvm-gen.UUCP (Stephen J. Hartley) writes:
...
+< -----------------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) !!
+< 
+
+I tried this and noticed that commands "redone" this way do not go
+through csh aliasing, i.e. if you have "mv" aliased to "mv -i" and
+then "redo" some previous command that had a "mv" in it, then you will
+have a plain "mv" redone and run the risk of clobbering a file.
+Does anybody know why the aliasing check is bypassed?

I don't know "why", but it has something to do with the way csh handles the
"if" expression at the end.  Changing it to:

	if (!-2:0 != !!:0) then
		!!
	endif

makes it work correctly (in "tcsh" and the csh that comes with ultrix 2.2)

Mike Khaw
-- 
internet: mkhaw@teknowledge.arpa
uucp:	  {uunet|sun|ucbvax|decwrl|uw-beaver}!mkhaw%teknowledge-vaxc.arpa
hardcopy: Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303

hartley@uvm-gen.UUCP (Stephen J. Hartley) (06/02/88)

From article <8805171730.AA22099@cope>, by goldman@cope.ucsf.edu (Eric S. Goldman):
< comp.sources.misc: Volume 3, Issue 20
< Submitted-By: "Eric S. Goldman" <goldman@cope.ucsf.edu>
< Archive-Name: redo
< 
< -----------------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) !!
< 

This script starts up a one-line-window edit session of the last command
on the bottom of the screen.  One can then use the hjkl keys to move around
the last 22 commands.  Any movement up (k) or down (j) adds another line
to the bottom of the screen (scrolls).  Is there any way to modify the
way "ex" is fired up in the script so that only one line at all times is
displayed at the bottom of the screen, i.e. a true one-line edit window
(movement up or down in the file overwrites the old line with the new line)?
Thanks for your wizardry!
-- 
Stephen J. Hartley, Dept Comp Sci Elec Eng, Univ Vermont, Burlington, VT  05405
CSNET:	hartley@uvm.EDU					(802) 656-3330, 862-5323
USENET:	...!uunet!uvm-gen!hartley, {decvax,ihnp4,linus}!dartvax!uvm-gen!hartley