[PATCH] ash: add support for history buffer

Dennis Groenen tj.groenen at gmail.com
Tue Jul 12 12:46:26 UTC 2011


On 07/12/2011 01:57 AM, Douglas Mencken wrote:

> Hey! history is good, at least for grepping inside it.
> And it's useful to have history left on re-login.
> History must be permanent, and removable by request.
You seem to have missed the point of the patch. That's probably my fault though, I guess I didn't elaborate it enough in the initial mail.
I'll go into a bit more detail in this mail then.

First of all, the history remains to be persistent; it's still loaded after starting a new shell, and you can still do everything with it as you're used to (e.g. grepping).
This patch only introduces a temporary location for the history file until the shell is exited. In other words: a buffer.

BusyBox writes to .ash_history after each and every command, which we don't want on e.g. mobile devices with a flash-based storage device.
Using a buffer helps reducing the amount of erase/write cycles on the storage medium

This patch basically makes ash do this:
1) User starts shell, copy $HOME/.ash_history to /tmp/.ash_hist_$USER (changeable with ASH_HIST_BUFFER_PATH)
2) During shell use, history is written to /tmp/.ash_hist_$USER in the _exact_ same way as BusyBox used to (i.e. after each command); nothing outside shell/ash.c is touched by my patch.
3) User exits shell, copy /tmp/.ash_hist_$USER back to $HOME/.ash_history

Assuming /tmp contains an in-memory filesystem, this should save quite a few writes to the storage medium.
Also, the above behaviour is only activated when ASH_HIST_BUFFER is set to y (which it isn't by default), so you're not forced to the new behaviour.

Please have a look at the code and you'll probably see 1:1 what I'm talking about. The code is relatively small and easy to read in my opinion.
If you, or anyone else, have any further questions, feel free to ask them.

--Dennis

P.s. I completely agree with your opinion on shell history.



More information about the busybox mailing list