From: Dominik Vogt <dominik.vogt@gmx.de>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: skipping duplicates in some zle functions
Date: Thu, 6 Nov 2003 09:54:51 +0100 [thread overview]
Message-ID: <20031106085451.GD28005@gmx.de> (raw)
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 ^_^ ^_^
next reply other threads:[~2003-11-06 8:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-06 8:54 Dominik Vogt [this message]
2003-11-06 15:31 ` Bart Schaefer
2003-11-07 9:34 ` Dominik Vogt
2003-11-11 13:34 ` Phil Pennock
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=20031106085451.GD28005@gmx.de \
--to=dominik.vogt@gmx.de \
--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).