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

Re: subsitutions and beginning of lines.



On Mon, 12 Oct 2015 08:53:21 -0700
Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:

> On 10/11/2015 07:26 PM, Daniel Shahaf wrote:
> > You could avoid parsing the line numbers (and unescaping the commands) 
> > altogether by accessing the history differently: 
> 
> > % print -r - $history[1004] echo foo 
> 
> I could never get that to work with anything besides a single 
> subscript.  I'd expect it
> to drive like any other array but nothing seems to work:
> 
>      print -lr - $history[-5,-1]
> 
> ... and the point of what I'm doing is to show a range.

It's an associative array, so you need the exact index as a decimal with
no leading zeros; ranges and reverse indices don't work.

% print ${(t)history}
association-readonly-hide-hideval-special

But you can fake something like that above up:


local -a myhist=() indices=({$((HISTCMD-5))..$((HISTCMD-1))})
integer ind
for ind in $indices; do
  myhist+=(${history[$ind]})
done


pws



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