zsh-users
 help / color / mirror / code / Atom feed
* Ability to set HISTNO to a certain position from within zshrc
@ 2003-09-11  6:21 Felix Rosencrantz
  2003-09-11 14:48 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Felix Rosencrantz @ 2003-09-11  6:21 UTC (permalink / raw)
  To: zsh-users

In certain situations when starting a new shell, I have an automated way to
determine a likely set of commands I will need to run and the order.   So, I
prime my history with these commands from my .zshrc using "print -s".

Now I find that I would also like to have my command line primed with one of
these lines, such that HISTNO is pointing to that line in the primed command
history.  I want to be able to use accept-line-and-down-history (or similar
widget) to allow me to quickly run through this list of commands if everything
goes smoothly.

Is there a way to start from a point in the primed history from my .zshrc?  It
seems like you have to be within a zle widget to modify HISTNO.  (HISTNO is
read only, but can be modified indirectly through zle widgets that change the
history position.)
 
-FR.



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ability to set HISTNO to a certain position from within zshrc
  2003-09-11  6:21 Ability to set HISTNO to a certain position from within zshrc Felix Rosencrantz
@ 2003-09-11 14:48 ` Bart Schaefer
  2003-09-13 22:07   ` Felix Rosencrantz
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2003-09-11 14:48 UTC (permalink / raw)
  To: zsh-users

On Sep 10, 11:21pm, Felix Rosencrantz wrote:
}
} Is there a way to start from a point in the primed history from my .zshrc?

Not exactly, but I think you can get the effect you want by doing:

print -s 'the first command in your sequence'
print -s 'the next command in your sequence'
print -s 'and so on'
print -s 'etc etc etc'
print -z 'the first command in your sequence'

If at this point you invoke accept-and-infer-next-history, you should end
up exactly where you want to be.

If the first command in your sequence is not unique among others in the
sequence, just make it so by doing

print -s ': BEGIN ; the first command in your sequence'
print -s ...
print -z ': BEGIN ; the first command in your sequence'

Rather than using 'print -s ...' you might consider placing the commands
in a file and loading them with 'fc -R'.  Of course, you still need the
final 'print -z' to set up the interactive part.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ability to set HISTNO to a certain position from within zshrc
  2003-09-11 14:48 ` Bart Schaefer
@ 2003-09-13 22:07   ` Felix Rosencrantz
  2003-09-13 23:19     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Felix Rosencrantz @ 2003-09-13 22:07 UTC (permalink / raw)
  To: zsh-users

Thanks Bart.

I've tried your suggestions.  The "fc" and the print -z work well.  And I bind
the "enter" key to point to accept-and-infer-next-history.

Though ainh has a couple problems.  It's not a replacement for accept-line.  It
won't accept if it can't infer.  Peter(?) recently modified
accept-line-and-down-history to accept even if it can't go down in history.  I
suspect ainh could be modified too.  Though maybe the current behavior is
preferred...

I wanted to start in the middle of history not the beginning.  So the lines
above the starting point contain commands that might need to be run, and the
starting line and following lines contain the likely sequence of commands to
run.

With the "print -z"/ainh solution I lose the ability to have the leading
commands.   I don't want to place them in history after the likely command
sequence, (so they are just above "print -z" line) since I don't want to
accidentally run them through a series of ainh commands.

It almost seems like there should be a infer-back-into-history, where it
determines the inferred line, and jumps to it in history.  Maybe even an
accept-and-down-history-or-infer, which accepts,  attempts to go down in
history, and if at the end of the history, attempts to infer the next command.


-FR.

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ability to set HISTNO to a certain position from within zshrc
  2003-09-13 22:07   ` Felix Rosencrantz
@ 2003-09-13 23:19     ` Bart Schaefer
  2003-09-25  6:21       ` Felix Rosencrantz
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2003-09-13 23:19 UTC (permalink / raw)
  To: zsh-users

On Sep 13,  3:07pm, Felix Rosencrantz wrote:
}
} I wanted to start in the middle of history not the beginning.  So the lines
} above the starting point contain commands that might need to be run, and the
} starting line and following lines contain the likely sequence of commands to
} run.
} 
} With the "print -z"/ainh solution I lose the ability to have the leading
} commands.

So use print -z followed by history-search-backward, followed by either
moving up through the history or executing accept-line-and-down-history.

If it's really too much to have to hit one extra key before hammering away
at Enter, set up a keymap (see bindkey -N) in which up-arrow is bound to
a user-defined widget that changes back to the default keymap and then
executes history-search-backward and finally executes up-history, and in
which Enter is bound to a user-defined widget that changes back to the
default keymap and then executes accept-line-and-down-history.  Install
that keymap right after your print -z.

} It almost seems like there should be a infer-back-into-history, where it
} determines the inferred line, and jumps to it in history.

Isn't that what history-search-backward does?

} Maybe even an accept-and-down-history-or-infer, which accepts,
} attempts to go down in history, and if at the end of the history,
} attempts to infer the next command.

I think all the tools are available to write this as a user-defined widget.
As a crude stab at it:

aadhoi () {
    local buffer="$BUFFER"
    if zle down-history
    then
    	zle up-history
	BUFFER="$buffer"
	zle accept-line-and-down-history
    else
	zle -U $'\exinfer-next-history\n'
	zle accept-and-hold
    fi
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ability to set HISTNO to a certain position from within zshrc
  2003-09-13 23:19     ` Bart Schaefer
@ 2003-09-25  6:21       ` Felix Rosencrantz
  0 siblings, 0 replies; 5+ messages in thread
From: Felix Rosencrantz @ 2003-09-25  6:21 UTC (permalink / raw)
  To: zsh-users

This is quite a bit later, but here it goes....
--- Bart Schaefer <schaefer@brasslantern.com> wrote:
> } It almost seems like there should be a infer-back-into-history, where it
> } determines the inferred line, and jumps to it in history.
> 
> Isn't that what history-search-backward does?
History-search-backward looks at the first word of the current line, and then
searches for the next line back in history that starts with the same first
word. 

The "infer" widgets are funkier search widgets, they look at the previous
history line, look back past that line in history for that same line, and then
return the line following it.  Though it looks like all the infer widgets copy
the inferred line, none change HISTNO back to that line.

> 
> } Maybe even an accept-and-down-history-or-infer, which accepts,
> } attempts to go down in history, and if at the end of the history,
> } attempts to infer the next command.
> 
> I think all the tools are available to write this as a user-defined widget.
> As a crude stab at it:
> 
> aadhoi () {
>     local buffer="$BUFFER"
>     if zle down-history
>     then
>     	zle up-history
> 	BUFFER="$buffer"
> 	zle accept-line-and-down-history
>     else
> 	zle -U $'\exinfer-next-history\n'
> 	zle accept-and-hold
>     fi
> }

I tried this. (And thanks for the code!)  Though, I wasn't able to get it to
hit the else case. (Probably I'm doing something silly.) I looked at the zshzle
man page, it doesn't really say what kind of return value to expect from
down-history.  I looked at the source code for downhistory (I didn't look at
the code for those functions it called) and it looked that it would always
succeed if nohistbeep was set(!?). I didn't have it set, but tried using setopt
to change it without success.

As I said in the original message, I just wanted to set HISTNO from my .zshrc.
Though that's not possible.  It seems like some simple functionality is
missing; the ability to go to a history entry, and the ability to figure out
what the last entry is.  In some ways it seems like the zle widgets are not
fully oriented towards writing zle widgets. 

Though it is very easy to modify history by adding entries to history.  Based
on the code you sent, it even seems like it is difficult within a widget to
figure out if you're at the end of history.  You have to do an indirect test,
attempt to do a down-history and if that fails you are at the end.  

-FR.


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-09-25  6:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-11  6:21 Ability to set HISTNO to a certain position from within zshrc Felix Rosencrantz
2003-09-11 14:48 ` Bart Schaefer
2003-09-13 22:07   ` Felix Rosencrantz
2003-09-13 23:19     ` Bart Schaefer
2003-09-25  6:21       ` Felix Rosencrantz

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).