From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pixar.com ([138.72.10.20]) by hawkwind.utcs.toronto.edu with SMTP id <2701>; Mon, 28 Sep 1992 18:41:05 -0400 Received: from copland.pixar.com by pixar.com (4.1/NBN-15/PIX-36) id AA02876; Mon, 28 Sep 92 15:40:58 PDT Received: by copland.pixar.com (/\==/\ Smail3.1.25.1 #25.14) id ; Mon, 28 Sep 92 15:40 PDT Message-Id: To: rc@hawkwind.utcs.toronto.edu Subject: Hacking the history mechanism in rc Date: Mon, 28 Sep 1992 18:40:46 -0400 From: Bruce Perens ------- I wanted to have a way to implement my own history mechanism without hacking rc to bits, so I added a "hook" for an external history mechanism. When my version of rc is about to process a command line, it checks to see if the user has defined an rc function "add_history". If so, it calls the user function with the command line in $1 . A simple definition of add_history is: fn add_history { echo -n $1 >> /usr/people/bruce/history_file } My version is a bit more complicated. It puts the last command in the window title, etc. I think this is a good change because: + It replaces 15 lines of hard-coded C with four lines. + It makes rc more versatile without adding code. + It preserves the existing functionality. I'm also experimenting with a "glob" function. The function is called before globbing a filename, with a list containing the arguments. If it recognizes any special characters that it handles, it calls an external module that expands them and returns the expanded list. I use this to implement ~name expansion as in c-shell without adding code to rc. I was inspired by an old Version 6 or Version 7 Unix shell that used an external "glob" program. I think there is a lot of room for work with "hook" functions. Through them, rc can be made a lot more versatile without adding code to rc itself. Bruce Perens