Path: utzoo!attcan!uunet!husc6!bbn!mit-eddie!uw-beaver!teknowledge-vaxc!mkhaw From: mkhaw@teknowledge-vaxc.ARPA (Mike Khaw) Newsgroups: comp.sources.d Subject: Re: v03i020: "redo" Keywords: csh history editing Message-ID: <22746@teknowledge-vaxc.ARPA> Date: 25 May 88 23:16:05 GMT References: <8805171730.AA22099@cope> <853@uvm-gen.UUCP> Reply-To: mkhaw@teknowledge-vaxc.UUCP (Mike Khaw) Organization: Teknowledge, Inc., Palo Alto CA Lines: 43 Posted: Wed May 25 16:16:05 1988 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