zsh-users
 help / color / mirror / code / Atom feed
* Re: search through alternative HISTFILE
@ 2013-08-06 14:09 Maarten Grachten
  0 siblings, 0 replies; 8+ messages in thread
From: Maarten Grachten @ 2013-08-06 14:09 UTC (permalink / raw)
  To: zsh-users

Hi, last update, hopefully.

I found out that when I just append several history files to generate 
ACC_HISTFILE, setting HISTNO to the number of lines (+1) in 
ACC_HISTFILE, does not necessarily point zle to the end of the history. 
I am not sure why this happens (maybe it has to do with duplicate 
removals in the internal history representation?). If the value of 
HISTNO set in this way turns out to be invalid, it seems to be reset to 
its original value. I think the correct way to deal with this is to use 
the end-of-history widget to move to the end of the newly loaded history.

The resulting widget is then like this:

function accumulated-history-incremental-search-backward () {
     fc -p $ACC_HISTFILE
     zle .end-of-history
     zle .history-incremental-search-backward
     fc -P
     zle .end-of-history
}

Maarten


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: search through alternative HISTFILE
@ 2013-08-06 10:11 Maarten Grachten
  2013-08-06 11:05 ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Maarten Grachten @ 2013-08-06 10:11 UTC (permalink / raw)
  To: zsh-users

Just for the record. I figured out that it is necessary to reset HISTNO 
to its old value after the search on accumulated history is done 
(otherwise the normal search will be confused):

function accumulated-history-incremental-search-backward () {
     fc -p $ACC_HISTFILE
     HISTNO=$(( $( wc -l < $ACC_HISTFILE ) + 1 ))
     zle history-incremental-search-backward
     fc -P
     HISTNO=$(( $( wc -l < $HISTFILE ) + 1 ))
}

Maarten


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: search through alternative HISTFILE
@ 2013-08-06  9:55 Maarten Grachten
  0 siblings, 0 replies; 8+ messages in thread
From: Maarten Grachten @ 2013-08-06  9:55 UTC (permalink / raw)
  To: zsh-users

Hi Peter,

Thanks a lot for the explanation, and the patch, it works perfectly! 
Based on your explanation however, I tried the following as well:

ACC_HISTFILE="${HOME}/.accumulated-history"

function accumulated-history-incremental-search-backward () {
     fc -p $ACC_HISTFILE
     HISTNO=$(( $( wc -l < $ACC_HISTFILE ) + 1 ))
     zle history-incremental-search-backward
     fc -P
}

i.e. before doing the search on the accumulated history, set the 
variable HISTNO to just beyond the last line of that history file. This 
also seems to work without the patch you provided, however I cannot 
really judge if there are any unintended side-effects with this approach.

Many thanks again for helping me out! I appreciate the effort.

Maarten


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: search through alternative HISTFILE
@ 2013-08-05 10:05 Maarten Grachten
  2013-08-05 18:52 ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Maarten Grachten @ 2013-08-05 10:05 UTC (permalink / raw)
  To: zsh-users

Dear Peter,

Thank you very much for your answer. Your use case is indeed similar, if 
slightly more complex. I had hoped I could reuse the existing 
history-incremental-search-backward widget, only changing the history 
before calling it. The relevant command (which you also use in your 
widget) seems to be "fc -p <NEWHISTFILE>". As I understand it, this 
pushes the current history and replaces it with a new history, read from 
<NEWHISTFILE>. This approach actually works when I use the fc -p command 
on the command line before hitting Ctrl-R, but when I wrap it in a 
widget it does not work:

# Define shell function to be used as widget:

function accumulated-history-incremental-search-backward () {
     fc -p "${HOME}/.accumulated-history"
     zle .history-incremental-search-backward
}

# Tell zsh to use the function as a widget:

zle -N accumulated-history-incremental-search-backward

# Bind Ctrl-i to the widget:

bindkey "^I" accumulated-history-incremental-search-backward

Is there any particular reason why calling fc -p inside the widget does 
not affect the history search?

Maarten


^ permalink raw reply	[flat|nested] 8+ messages in thread
* search through alternative HISTFILE
@ 2013-08-02 10:38 Maarten Grachten
  2013-08-02 11:08 ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Maarten Grachten @ 2013-08-02 10:38 UTC (permalink / raw)
  To: zsh-users

Dear zsh users,

As part of an attempt to archive my command line history, I have a need 
for bck-i-search (as normally invoked by Ctrl-R), but with a history 
file that is not $HISTFILE, that is, a different file from that which 
the current shell uses for saving its history.

As I envision it, Ctrl-R would still search through the current shell's 
history (i.e. through $HISTFILE), and another key binding would search 
through an alternative but constant histfile (say 
$HOME/.accumulated-history).

Is this possible, and if so, can any of you give me a hint as to how to 
achieve it?

Many thanks in advance!

Maarten


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

end of thread, other threads:[~2013-08-06 14:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-06 14:09 search through alternative HISTFILE Maarten Grachten
  -- strict thread matches above, loose matches on Subject: below --
2013-08-06 10:11 Maarten Grachten
2013-08-06 11:05 ` Peter Stephenson
2013-08-06  9:55 Maarten Grachten
2013-08-05 10:05 Maarten Grachten
2013-08-05 18:52 ` Peter Stephenson
2013-08-02 10:38 Maarten Grachten
2013-08-02 11:08 ` Peter Stephenson

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