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

Re: [PATCH] Per-directory history implementation

On 2020-01-17 18:46:21 +0200, Dan Aloni wrote:
> This change is an attempt to implement this feature straight into zsh,
> so that its entry pruning and history file locking logic cover it as
> well.
> NOTE: There is external plugin that tries to implement this in the
> following manner: 1) switching the history file with current directory
> change to maintain a separate one, and reloading the zsh history each
> time it happens 2) maintaining the global history file in addition.
> While I wanted that plugin to work for me, it felt far from perfect and
> its downsides were too great for me.

What are these downsides?

I think that a solution written purely in zsh would be cleaner and
more flexible:
  * The user may want to change other things when switching
  * The user may want to change the history on other occasions.

Hook functions are nice for this kind of things.

> This is a first version, so I'm guessing there's much to iron out.
> --
> Conditional on the activation of the `extended_history` feature, these
> changes implement a `histsavecwd` feature. The current directory of the
> command is added to each command in the history file, in this manner:
>     : 1579121354 /home/user:0;ls -l
> Instead of the old format:
>     : 1579121354:0;ls -l
> In addition, the 'fc' commands get a '-c' option that filters out
> commands not pertaining to the current directory. This can serve to
> implement a command similar to `Ctrl-R` showing only the per-directory
> history.
> Note that that pathnames that contain the ':' character are not
> supported for now - these are expected to mess up history parsing. We
> should escape the `:` character if we want to support them, or change
> the format altogether.

That's a security issue, as the user may want/need to switch to any
directory, possibly belonging to other users. The format should be
able to handle any possible pathname (including with \n characters).

Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

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