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

Re: prexec never gets empty string?



On Feb 16,  9:11am, Derek Gleim wrote:
}
} As an aside, I'd still like to be able to get the prompt expansion `%!` to
} always show the number to be assigned to the next command...
} 
}     % PROMPT='%! >' zsh --no-rcs --histignorespace
}     1 > true ignore me
}     2 >this command will really be event 1
}     2 >

Hrm.  The history number isn't ajusted until the hend() call of the input
command following the one to be ignored.  That's because the previous
line actually CAN be referenced as (in the example above) !1 while you
are at the prompt that says "2 > ".

So there's an inherent conflict here; for a short while, there effectively
are two history events both numbered the same.  You're either going to be
misled about what the last command was numbered, or about what the current
command will be numbered.  This actually works well for HIST_IGNORE_DUPS
because the two identical commands are collapsed onto the same number, but
in other cases cases you end up with !N references where N finds something
that doesn't match your terminal scrollback.

Possible approaches:

(0) Do nothing.

(1) Make the numbering match the "what it will be" case.
    (a) Introduce a second history counter used only in prompt expansion
        that skips incrementing at hbegin() time [rather than hend()].
    (b) Do a significant rework of hist.c so the "curhist" variable can
        serve that role correctly.

(2) Rework history to leave holes in the number sequence when an event
    is skipped.  I believe this is already done for HIST_IGNORE_ALL_DUPS
    and HIST_EXPIRE_DUPS_FIRST when the older duplicate is dropped.  The
    history is stored in a hash table, so event numbers are just keys in
    the hash and holes are (I think) not an issue.

I'm not going to jump in on implementing any of the above any time soon,
but perhaps we can reach consensus on which is the best thing and then
somebody else can tackle it.



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