[comp.emacs] csh emacs alias

tcu@expya.UUCP (Tony Curtis) (12/20/87)

Well, just when you thought there were going to be no more
replies - here's one. The problems with some of the replies
earlier (which I now can look back on wistfully) were mainly
to do with "jobs". If people had paid attention to the
comp.unix.questions discussions on that command then replies
involving piping jobs through grep, sed etc. would have been
omitted (for reasons which should be clear in those articles
in c*.u*.questions)

It took a lot of thinking about, but I've got a solution for
you which runs fairly fast, doesn't source anything and even
uses the Bourne shell.

Consider the following sequence
-------------------------------------------------------------------------------
jobs > /tmp/jtmp$$
set noglob                  # for echoing wildc*rds (normally off)
eval `sh -c "if grep -s emacs /tmp/jtmp$$ ; then echo %\?emacs; else echo /usr/local/bin/emacs \!*; fi"`
unset noglob
-------------------------------------------------------------------------------

What this does is to get the current job status in a file /tmp/jtmp$$,
set noglob, and then do the clever bit in sh. 

The clever bit checks to see if the pattern 'emacs' appears in the file
/tmp/jtmp$$.  If it does, then echo %?emacs, to reinvoke the latest job
containing again the pattern 'emacs', or if it doesn't then actually
invoke the editor for real and give full path to avoid alias loops
(obviously substitute your local path for the one I've got).  You could
then rm /tmp/jtmp$$ if you wanted but I can't be bothered and it'll only
be a small file, so it may as well be left alone (after all it will get
used a lot).  You also might like to change /tmp/jtmp$$ to $HOME/.jtmp so
that everyone has a file in their own filespace (according to taste ...)

Here's the alias I got to work on our machine

-------------------------------------------------------------------------------
alias emacs 'jobs > /tmp/jtmp$$; set noglob; eval `sh -c "if grep -s emacs /tmp/jtmp$$; then echo %\?emacs ; else echo /usr/local/bin/emacs; fi"` ; unset noglob'
-------------------------------------------------------------------------------

Hope this works for you!!

Tony


-- 
.=- ADDRESS SOON TO BE CHANGED ... -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.
| Tony Curtis, Experimental Officer = {tcu,occam}@{uk.ac.ex.cs,expya.UUCP}  |
| Exeter Uni., Comp. Sci. Dept., Prince of Wales Road, Exeter, Devon EX4 4PT|
`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-'