Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
skipping duplicates in some zle functions
- X-seq: zsh-users 6744
- From: Dominik Vogt <dominik.vogt@xxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: skipping duplicates in some zle functions
- Date: Thu, 6 Nov 2003 09:54:51 +0100
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Reply-to: zsh-users@xxxxxxxxxx
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 ^_^ ^_^
Messages sorted by:
Reverse Date,
Date,
Thread,
Author