Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!pprg.unm.edu!hc!lll-winken!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re^2: C Shell history, backprimes Q's -- Noddy Level Message-ID: <2294@solo11.cs.vu.nl> Date: 13 Apr 89 00:01:18 GMT References: <2251@solo8.cs.vu.nl> <487@lakart.UUCP> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 162 dg@lakart.UUCP (David Goodenough) writes: \From article <2251@solo8.cs.vu.nl>, by maart@cs.vu.nl (Maarten Litmaath): \> ian@hpopd.HP.COM (Ian Watson) writes: \> \I've just entered a command 'foo bar parm', when what I wanted was \> \'foobar parm'. ... \> \> Welcome to csh! There's no way to achieve what you want :-( \Actually there is. I already posted another follow-up getting that straight: I should have said no way using the caret sign ^ Use !:0!* instead. [source of `redo' deleted] How about the following? (Works with cshs without `source -h' too.) : This is a shar archive. Extract with sh, not csh. : This archive ends with exit, so do not worry about trailing junk. : --------------------------- cut here -------------------------- PATH=/bin:/usr/bin:/usr/ucb echo Extracting 'cmde.c' sed 's/^X//' > 'cmde.c' << '+ END-OF-FILE ''cmde.c' X/* X * To use this history command line editing facility, set the following alias: X * X * alias ! 'cmde ~/.cmde ! && source ~/.cmde' X * X * (Put 'cmde' in your path.) X * If your history character is some other character than '!', just change X * EVERY occurrence of '!' into your char. X * When you want to invoke 'cmde', just type '!' and hit return. X * Now you can type the remaining characters to complete the history X * reference, just as if you typed them adjacent to the '!', e.g.: X * X * % ! X * d X * or X * % ! X * ?foo X * or X * % ! X * -3 X * or X * % ! X * 56 X * X * Type '!' or just return to obtain the previous command, or ^D to quit the X * editor. If you didn't quit, you'll end up in a 1 line vi editor; type 'ZZ' X * or ':x' to end the editing. X * Author: Maarten Litmaath @ VU Informatika Amsterdam (maart@cs.vu.nl) X */ X X#include X X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X FILE *fp, *fopen(); X char h, *gets(), buf[512], *adjust(), *check(); X int c; X X X if (argc != 3 && argc != 4) { X fprintf(stderr, "Argc error.\n"); X exit(1); X } X X if (!(fp = fopen(argv[1], "w"))) { X perror(argv[1]); X exit(1); X } X X h = *argv[2]; X X if (argc == 3) { /* first pass */ X if (!gets(buf)) X exit(1); X X fprintf(fp, X "echo \"%c%s:q\" | %s %s %c 2; ex +open %s; source %s\n", X h, !*buf || *buf == h ? "-2" : X *buf == '-' ? adjust(buf) : X *buf == '?' ? check(buf) : buf, X argv[0], argv[1], h, argv[1], argv[1]); X X exit(0); X } X X /* second pass */ X X while ((c = getchar()) != EOF) { X if (c == h) { X switch (c = getchar()) { X case ' ': X case '\t': X case '\n': X case '=': X case '(': X break; X default: X putc('\\', fp); X } X putc(h, fp); X } X putc(c, fp); X } X X exit(0); X} X X Xchar *adjust(s) Xchar *s; X{ X static char buf[8] = "-"; X char *sprintf(); X X X if (*++s < '0' || *s > '9') X return --s; X X (void) sprintf(buf + 1, "%d", atoi(s) + 1); X X return buf; X} X X Xchar *check(s) Xregister char *s; X{ X static char buf[32] = "?"; X register char *p = buf + 1; X char *save = s++; X X X while (*p = *s++) X if (*p++ == '?') X return save; X *p++ = '?'; X *p = '\0'; X return buf; X} + END-OF-FILE cmde.c chmod 'u=rw,g=r,o=r' 'cmde.c' set `wc -c 'cmde.c'` count=$1 case $count in 2097) :;; *) echo 'Bad character count in ''cmde.c' >&2 echo 'Count should be 2097' >&2 esac exit 0 -- "If it isn't aesthetically pleasing, |Maarten Litmaath @ VU Amsterdam: it's probably wrong." (jim@bilpin). |maart@cs.vu.nl, mcvax!botter!maart