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

Re: .zsh_history



On Fri, Apr 14, 2023 at 10:28 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
>
> On 2023-04-14 07:36, Felipe Contreras wrote:
>
> > I do remember that one's control of history is essentially perfect, you
> >> can get just about anything you want.  History is one of those features
> >> of zsh that is tractable and understandable without too much head
> >> scratching and without any weird gotchas.
> > I couldn't disagree more.
> >
> It could very well be that a closer examination than I've made would
> reveal various mysteries and gotchas.  All I can say is that I've never
> wanted something from history that it couldn't provide.

Yes, that is true.

My current history configuration is *exactly* what I want. I have a
large ~/.history file that is updated every time I type a command, but
it doesn't affect any currently running shell (inc_append_history).

In addition to that, every command I type is stored in a separate
historical file that I use to generate statistics (top 20 commands and
top 20 directories).

So let me clarify my statement: the zsh history configuration is very
powerful and simple, and it allows everyone to configure zsh the way
they want it.

*But* that doesn't mean everyone understands all the configurations.
So I think a more accurate statement would be that the configuration
is unidirectional: everyone understands their own configuration,
because they had an idea of what made sense, looked for a way to
achieve it, and found it. But other people have other ideas, and their
configuration isn't necessarily understood by others.

> One exception: "$ echo one; echo two; echo three" ... you can't,
> AFAICT, break up the line into it's component commands.

Is that really a zsh thing? I think the same happens in all shells.

> I'd sure love to be able to pull just the text of a single command.

I'm 100% certain you can do that, but not with history expansion, you'll
need to use zle for that.

To me (and I'm not sure if this analogy will land), it's like trying to
update CSS dynamically using CSS, when JavaScript is the tool for that.

This is not something I generally use, but I checked the documentation
of default zle widgets, and you can copy the previous word with
CTRL+ALT+_ and you can switch back and forth the previous two words with
ALT+t.

So you can write zle widgets to do anything you want to do with the
current line, but that's significantly different from history
substitution (e.g. !!0).

Cheers.

-- 
Felipe Contreras




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