zsh-workers
 help / color / mirror / code / Atom feed
* The number of the most recent history event
@ 2001-06-30 20:18 Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2001-06-30 20:18 UTC (permalink / raw)
  To: zsh-workers

$#history is the number of history -entries-, NOT the number of history
-events-; it never exceeds $HISTSIZE.  So, how does one get the number of
the most recent event?  I've come up with two ways:

1.	$[${(%):-%h}-1]

The $[...-1] is necessary because %h expands to the number of the entry
that is -about to be- filled in.

2.	$[${${(@O)${(@kl:5:)history}}[1]}]

The outer $[...] is necessary to force integer interpretation, thereby
stripping off the leading spaces from (l:5:), and the two (@) are needed
because $[...] causes a double-quote context.  Of course (l:5:) assumes
you haven't executed more than 99999 commands in the current shell.

If we were to add an (n) flag, e.g. (On) and (on) sort numerically (like
(Oi) and (oi) do case-independently), ${${(Onk)history}[1]} would do it,
as would ${${(onk)history}[-1]} which might be a bit clearer.

Or maybe we should just add the history number to the parameter module?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-06-30 20:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-30 20:18 The number of the most recent history event Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).