Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: per-directory history?

On Apr 11, 12:08pm, Matt Pharr wrote:
} Subject: per-directory history?
} I was thinking about the history stuff in zsh last night, and it struck me
} that it would be neat to have a per-directory history mechanism.
} Is this easily done at the user level given zsh's current set of features?

Relatively easily, yes.  The main issues are security (avoid loading a
history left for you by someone malicious (though this isn't too bad as
the commands aren't actually executed)), collision-avoidance in shared
directories, and handling of non-writable directories.

The solution looks something like

    chpwd() {
	local ohistsize=$HISTSIZE
    	fc -W ~-/.history.$UID
	HISTSIZE=0		# Discard previous dir's history
	HISTSIZE=$ohistsize	# Prepare for new dir's history
	fc -R ./.history.$UID

There's a whole bunch of other stuff that has to be thrown in to set up
the initial history when the shell first starts and to make sure you don't
try to write where you can't or read where there is no file; but you get
the idea.

A more complex solution would encode the path of any directory cd'd to as
a file name relative to a writable subdir of your home directory, so that
you are guaranteed to be able to write and to have control over what you

} What do folks think about incorporating something along these lines in a
} future release?

I don't think it's easily enough generalized to be done as a builtin op.
Certainly a sample script to set it up would be interesting to include.

Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

Messages sorted by: Reverse Date, Date, Thread, Author