diff options
| -rw-r--r-- | history.1 | 15 | ||||
| -rw-r--r-- | history.c | 14 |
2 files changed, 24 insertions, 5 deletions
@@ -176,13 +176,14 @@ matched before a command is selected. Substitutions may also be specified on the command line. These have the syntax: .Ds -.Ic old : new +.Ic old :[:...] new .De .PP (Note that the .I old pattern is used as a search-limiting pattern also.) -Substitutions happen on the first match. +Substitutions happen from left to right and are repeated according to the +number of colons specified. .PP Finally, if the program was invoked as .RI `` -- '' @@ -241,3 +242,13 @@ reinterpretation: .Cr " eval $comm" .Cr " }" .Cr "}" +.De +.PP +Stuttering the `:' in a substitution allows things like: +.Ds +; prog 1 2 3 abc > /very/long/path/abc.out +etc. +- prog abc::xyz +prog 1 2 3 xyz > /very/long/path/xyz.out +; +.De @@ -26,6 +26,7 @@ static const char id[] = "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $"; static struct { char *old, *new; + int reps; /* no. of repetitions. i.e. 1 means sub twice. */ } *replace; static char **search, *progname, *history; @@ -296,8 +297,12 @@ int main(int argc, char **argv) { search[nsearch++] = argv[i]; else { *(char *)s = '\0'; /* do we confuse ps too much? */ + replace[nreplace].reps = 0; + while(*(++s) == ':') { + replace[nreplace].reps++; + } replace[nreplace].old = argv[i]; - replace[nreplace].new = s + 1; + replace[nreplace].new = s; nreplace++; } @@ -312,8 +317,11 @@ next: s = getcommand(); for (i = 0; i < nreplace; i++) if (!isin(s, replace[i].old)) goto next; - else - s = sub(s, replace[i].old, replace[i].new); + else { + int j; + for (j = 0; j <= replace[i].reps; j++) + s = sub(s, replace[i].old, replace[i].new); + } if (editit) { s = edit(s); if (s == NULL) |