The scope of shell history

August 3, 2007

One of the little divides in Unix is the one between people who set up their shell to have a per-shell command history (a local history) and the people who set their shell up to use a global history.

While I know perfectly sane and sensible people who are in the global history camp, I am firmly on the local history side, because to me my shell history is contextual. When I hit cursor up or tell a shell to redo the last command, I want it to do redo the command that is right there in that window; I do not want it to redo the last command I did anywhere. (In fact, I doubt I could keep track of the last command I did.)

I suspect that a lot of sysadmins will fall into the local history side. Sysadmins operate in so many different contexts, some of which are split apart by necessity and cannot be joined, so it's very hard to have a truly global history that covers every command, on every machine, as every user. My guess is that once people start working with only semi-global history that they will prefer to go whole hog to local history.

Although I don't know if any shell supports it, there is an intermediate option: maintain both a local history and a common global history, but only look at the global history if the local history is exhausted. That way you keep local context but also get to pull back that neat ad-hoc pipeline you came up with two days ago in a window that you have long since closed down.

(Before you tell me about it, this is not quite what bash does; it freezes the 'global' history the moment you start it. Bash uses its own hybrid model that makes my head hurt.)


Comments on this page:

From 194.8.197.204 at 2007-08-04 11:51:40:

What I really want is local history, but at the end of the session, the local history, and only the local history (ie. not the history loaded from disk at startup), but all of the local history should be appended to the history file at once. That way I wouldn’t lose history when I use several shells concurrently, but context would still be preserved.

Aristotle Pagaltzis

By cks at 2007-08-04 15:22:49:

The truly global shell histories I've seen don't load the global history once on shell startup; instead they keep referring to it all the time, so you can literally type a command in one window and then immediately re-execute it in another. This is why it's so effective at destroying context.

(The typical implementation puts all the commands in a file. I believe some people keep a window that tails the history file, so they can see at a glance what the most recent commands are.)

From 194.8.197.205 at 2007-08-04 23:25:34:

I know what you mean by global history.

The funny thing is, what I want turns out to be very simple in bash: “shopt -s histappend” does exactly that. To think that I could have added it to my .bash_profile years ago and saved myself so much pain… Thanks for unwittingly giving me the kick in the pants that I needed to find this out. :-)

Aristotle Pagaltzis

Written on 03 August 2007.
« Using WSGI for performance tuning
Weekly spam summary on August 4th, 2007 »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Fri Aug 3 23:13:46 2007
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.