zsh-users
 help / color / mirror / code / Atom feed
* skipping duplicates in some zle functions
@ 2003-11-06  8:54 Dominik Vogt
  2003-11-06 15:31 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Vogt @ 2003-11-06  8:54 UTC (permalink / raw)
  To: Zsh Users

I'm already using a fairly complicated function bound to Up and
Down that combines up/down-line-or-search and
history-beginning-search-forward/backward (see below).

I want to enhance it so that it skips lines that are identical
to the line that is currently displayed.  E.g. If I have the
following lines in the history (latest one at the bottom):

  ls /tmp
  cd /tmp
  ls foo*
  rm foo
  rm foobar
  ls foo*
  cd

Now I type

  $ ls f<crsr-up>
        ^
        |___ cursor

and get

  $ ls foo*
        ^
        |___ cursor

Now I press <crsr-up> again, and with the current functions, the
second "ls foo*" entry is selected.  But I'd rather skip that one
and proceed to "ls /tmp" immediately.

Any hints how to do this?

------------------------------- snip ----------------------------
function __up_or_down_line_or_beginning_search {
if [[ $LASTWIDGET != down-line-or-beginning-search &&
      $LASTWIDGET != up-line-or-beginning-search ]]; then
    local LBUFFER_STRIPPED="${LBUFFER/#[       ]#/}"
    if [[ $RBUFFER == *$'\n'* ||
          ${LBUFFER_STRIPPED} == "" ]]; then
        __last_up_line=up-line-or-history
        __last_down_line=down-line-or-history
    else
        LBUFFER_STRIPPED="${LBUFFER_STRIPPED/#[^   ]#[   ]#/}"
        if [[ "$LBUFFER_STRIPPED" == "" ]]; then
            __last_up_line=up-line-or-search
            __last_down_line=down-line-or-search
        else
            __last_up_line=history-beginning-search-backward
            __last_down_line=history-beginning-search-forward
        fi
    fi
fi
}
zle -N __up_or_down_line_or_beginning_search

function up-line-or-beginning-search {
    __up_or_down_line_or_beginning_search
    zle .${__last_up_line:-beep}
}
zle -N up-line-or-beginning-search

function down-line-or-beginning-search {
    __up_or_down_line_or_beginning_search
    zle .${__last_down_line:-beep}
}
zle -N down-line-or-beginning-search

bindkey "\e[A" up-line-or-beginning-search   # Cursor up
bindkey "\e[B" down-line-or-beginning-search # Cursor down
------------------------------- snip ----------------------------

Ciao

Dominik ^_^  ^_^


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

* Re: skipping duplicates in some zle functions
  2003-11-06  8:54 skipping duplicates in some zle functions Dominik Vogt
@ 2003-11-06 15:31 ` Bart Schaefer
  2003-11-07  9:34   ` Dominik Vogt
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2003-11-06 15:31 UTC (permalink / raw)
  To: zsh-users

On Nov 6,  9:54am, Dominik Vogt wrote:
}
} I want to enhance it so that it skips lines that are identical
} to the line that is currently displayed.

I don't suppose `setopt hist_find_no_dups' does what you want?

If not, have you considered `setopt hist_ignore_all_dups' so that the
duplicate lines are never entered into the history in the first place?


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

* Re: skipping duplicates in some zle functions
  2003-11-06 15:31 ` Bart Schaefer
@ 2003-11-07  9:34   ` Dominik Vogt
  2003-11-11 13:34     ` Phil Pennock
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Vogt @ 2003-11-07  9:34 UTC (permalink / raw)
  To: zsh-users

On Thu, Nov 06, 2003 at 03:31:41PM +0000, Bart Schaefer wrote:
> On Nov 6,  9:54am, Dominik Vogt wrote:
> }
> } I want to enhance it so that it skips lines that are identical
> } to the line that is currently displayed.
> 
> I don't suppose `setopt hist_find_no_dups' does what you want?

That's exactly what I need.  Thanks.

> If not, have you considered `setopt hist_ignore_all_dups' so that the
> duplicate lines are never entered into the history in the first place?

I like to repeat commands I have typed recently in sequence, so
this isn't quite what I want.  E.g:

  $ vi foo.c
  $ gcc -o foo foo.c
  $ ./foo
  3x<Up>
  $ vi foo.c
  3x<Up>
  $ gcc -o foo foo.c
  3x<Up>
  $ ./foo
  
...

Ciao

Dominik ^_^  ^_^


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

* Re: skipping duplicates in some zle functions
  2003-11-07  9:34   ` Dominik Vogt
@ 2003-11-11 13:34     ` Phil Pennock
  0 siblings, 0 replies; 4+ messages in thread
From: Phil Pennock @ 2003-11-11 13:34 UTC (permalink / raw)
  To: zsh-users

On 2003-11-07 at 10:34 +0100, Dominik Vogt wrote:
> I like to repeat commands I have typed recently in sequence, so
> this isn't quite what I want.  E.g:

infer-next-history ?

-- 
2001: Blogging invented. Promises to change the way people bore strangers with
banal anecdotes about their pets. <http://www.thelemon.net/issues/timeline.php>


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

end of thread, other threads:[~2003-11-11 13:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-06  8:54 skipping duplicates in some zle functions Dominik Vogt
2003-11-06 15:31 ` Bart Schaefer
2003-11-07  9:34   ` Dominik Vogt
2003-11-11 13:34     ` Phil Pennock

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