[net.sources] Perversions of source -h and other csh aliases

aburt@koala.uucp (Andrew Burt) (08/10/84)

For your enjoyment, here are some interesting lunch hour csh aliases that 
I've created.

My personal favorite is the "history editor" -- allows you to edit
you csh history.  The alias:

	alias hed history -h !* > $hed; vi + $hed; source -h $hed

will allow you to invoke 'vi' on your current history.  (If, for
instance, you typed in a long, tedious line and put in an extra space,
among other things.  The ^...^...  mechanism to remove it can be quite
tedious; 'hed's is easy.)  Before anyone starts flaming that vi is too
slow, history can do it (even if it's tough to type and you're prone to
more typos doing the history), etc. -- if you don't like it, don't use it.

Hed works particularly well if you move the command in question to the
end of the file; then '!!' will execute it after you ZZ from vi.  The
only drawback to this is that it trashes your current event numbers
(they get incremented during the source -h).  By using 'hed 10' you
only edit the last 10 entries in your history.  A temp file, which I
keep in $hed (set to /tmp/hed.$$ from my .login), is used each time for
the history.  Obvious changes to this are to use /tmp/hed.$$ straight
out and add "rm /tmp/hed.$$" to the end of the list.  If you don't like
waiting for the rm, and your /tmp doesn't get cleared out periodically,
put a # in front of the name to make it a disposable file.

This may be slower than the vi/emacs mode in the ksh I keep hearing about, but
it does give the functionality.

A slight modification to 'hed'...

	alias hedf history -h !-0:1 > !-0:2; vi + !-0:2; source -h !-0:2

allows you to specify a file to place the history into instead of a temp
file.

Another modification yields:

	alias heh echo \!* > $hed; vi + $hed; source -h $hed

Which lets you edit then add to your history a specific history sequence.
'Heh' for History edit history.

By inserting a 'source \!-0:2' before the source -h in any of the
above has the effect of executing the commands AND placing them on the
history list (from which we may conclude that 'alias so source \!* ; 
source -h \!*' is a useful item: it sources a file then places each line
into your history).

On rare occasions you'll have to put extra quotes/escapes around things
when editing the temp file so it gets sourced right.  Particularly around
aliases with raw history substitutions in them (the \!* type of thing).
The easiest is to try it first; if it fails, edit it again.  After all,
two 'hed's are better than one...

Regarding the use of !-0:1 instead of !:1 for the first argument to the
current command -- At least one csh is known to accept the former but not
the latter.  (The same csh dumps core (therefore logging you out) on receipt
of the !# history selector.  This is version 1.0 of 4.2BSD csh on a Sun-2.
The 1.1 csh exhibits this behavior:

	echo a !#
	a echo a echo

adding an extra arg 0 to the end.  Is this common to other cshs out there?)

So, for those whose csh's allow !:1, use that where I have !-0:1, etc.

Another interesting perversion is an alias'd whereis:

	alias wheres ls -l \{'`echo $path | sed "s/ /,/g"`'\}/'`echo \!-0:1 | sed "s/^./[&]/"`'

It does an ls -l on every file (passed as arg 1) in any directory on
your current path.  (No aliases, though adding an if at the front
should do the trick.)  The idea is to turn your $path list into a comma
separates list, stick that between {}, and append / and arg 1 to that.
Alas, if the file doesn't exist in one of the directories, you get
errors from ls saying it doesn't exist in a given directory.  So, arg 1
is turned into a pattern, which is allowed to fail; the pattern is,
e.g., foo --> [f]oo.  So the second arg to ls only expands to the
existing files.
-- 
Andrew Burt
Sigma Design, Inc.
{allegra,amd,hao,ucbvax}!nbires!koala!aburt