From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from postman.osf.org ([130.105.1.152]) by hawkwind.utcs.toronto.edu with SMTP id <2714>; Tue, 29 Sep 1992 10:38:19 -0400 Received: from earth.osf.org by postman.osf.org (5.64+/OSF 1.0) id AA20692; Tue, 29 Sep 92 10:38:05 -0400 Received: by earth.osf.org (5.64/4.7) id AA22337; Tue, 29 Sep 92 10:38:04 -0400 Date: Tue, 29 Sep 1992 10:38:04 -0400 From: rsalz@osf.org Message-Id: <9209291438.AA22337@earth.osf.org> To: byron@netapp.com, rc@hawkwind.utcs.toronto.edu Subject: Re: recent rc hacks I like Byron's idea, but I like even more the idea of not needing these little scripts or programs lying around. And even more perversely, I like the idea of using big monstrous perl to tame the history of small elegant rc. So, the following 45-line perl script. It uses $histlog to say where to write the history log file. I don't know why but if I invoked this directly then my shell stopped adding to the history (actually, I do sort of know why; I'd calll it a bug) Using this function helps: fn trimhist { perl $h/bin/trimhist && history=$history } #! /usr/bin/perl -- $size = 50; $history = $ENV{'history'} || die "No \$history environment variable, stopped"; $old = $history . '~'; rename($history, $old) || die "Can't rename $!, stopped"; open(IN, $old) || die "Can't open $old $!, stopped"; ## Parse $history, filling in @lines with last unique occurence of each ## command. %commands = (); @lines = (); $count = 0; line: while ( ) { chop; next line if /^-/ || /^; / || /^$/; $lines[$commands{$_}] = "" if defined $commands{$_}; $commands{$_} = $count++; push(@lines, $_); } close(IN) || die "Can't close $history $!, stopped"; @lines = grep($_ ne "", @lines); ## Open new output open(OUT, ">$history") || die "Can't open $history $!, stopped"; ## Print last "$count" lines. $start = $#lines - $size; $start = 0 if $start < 0; $count = 0; foreach ( @lines[$start .. $#lines] ) { print OUT $_, "\n"; $count++; } close(OUT) || die "Can't close $history $!, stopped"; unlink($old) || die "Can't remove $old $!, stopped"; ## Update $histlog (unset it to not do that). $log = $ENV{'histlog'} || exit(0); open(OUT, ">>$log") || die "Can't open $log $!, stopped"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); printf OUT "%4d/%2.2d/%2.2d %d\n", $year + 1900, $mon + 1, $mday, $count; close(OUT) || die "Can't close $log $!, stopped";