zsh-users
 help / color / mirror / code / Atom feed
From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh users <zsh-users@sunsite.dk>
Subject: incr. search: skip duplicates on the same history event
Date: Sat, 16 Jun 2007 20:31:07 +0200	[thread overview]
Message-ID: <20070616183107.GC5199@fsst.voodoo.lan> (raw)

Hey list,

Someone on IRC came up with the following question:

Say, you got a few history events that got the string 'make' in them:

  % make depend
  % make clean ; make all ; sudo make install

After a few more commands, you do a
'history-incremental-search-backward' for 'make' and get back the last
event with the three make calls on one line. Now you can reinvoke
'history-incremental-search-backward' again to jump back to earlier
occurrences of 'make' in the history:

  % make clean ; make all ; sudo make install
    ^            ^               ^
    |            |               |
    |            |               \-- ^Rmake
    |            |
    |            \-- 1st time you hit ^R after making
    |                your initial search.
    |
    \-- after hitting ^R for the 2nd time you end up here.

Now, the idea is to after searching backwards for the first time
(^Rmake), hitting ^R again, to go further backwards should ignore any
other occurrences of 'make' in the current history event and jump
directly to the next history event containing 'make' ('make depend')
in the example above.

I have been playing around to get this working and had a few rather
complex solutions, that all failed somehow. :-)

So, I took another approach and the closest I got (which works) is the
following. It exists the incremental search and re-enters it if you
continue typing. That is not an exceptionally nice solution and it
would require additional tweaking to become usable.

[snip]
self-insert () {
  if [[ $LASTWIDGET == incsearch ]] ; then
    zle history-incremental-search-backward $LASTSEARCH
  fi
  zle .self-insert
}
zle -N self-insert
incsearch () {
  if [[ $LASTWIDGET == incsearch ]] ; then
    zle history-search-backward
  else
    zle history-incremental-search-backward
  fi
}
zle -N incsearch
bindkey '^r' incsearch
[snap]

However, I hope that someone has got a better idea to solve this.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


             reply	other threads:[~2007-06-16 18:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-16 18:31 Frank Terbeck [this message]
2007-06-16 19:03 ` Richard Hartmann
2007-06-17  0:32   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070616183107.GC5199@fsst.voodoo.lan \
    --to=ft@bewatermyfriend.org \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).