|
|
@@ -7,6 +7,7 @@
|
|
|
|
# Copyright (c) 2011 Sorin Ionescu
|
|
|
|
# Copyright (c) 2011 Sorin Ionescu
|
|
|
|
# Copyright (c) 2011 Vincent Guerci
|
|
|
|
# Copyright (c) 2011 Vincent Guerci
|
|
|
|
# Copyright (c) 2016 Geza Lore
|
|
|
|
# Copyright (c) 2016 Geza Lore
|
|
|
|
|
|
|
|
# Copyright (c) 2017 Bengt Brodersen
|
|
|
|
# All rights reserved.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
@@ -39,34 +40,32 @@
|
|
|
|
##############################################################################
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# declare global variables
|
|
|
|
# declare global configuration variables
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
: ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold'}
|
|
|
|
|
|
|
|
: ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold'}
|
|
|
|
|
|
|
|
: ${HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'}
|
|
|
|
|
|
|
|
: ${HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''}
|
|
|
|
|
|
|
|
: ${HISTORY_SUBSTRING_SEARCH_FUZZY=''}
|
|
|
|
|
|
|
|
: ${HISTORY_SUBSTRING_SEARCH_PREFIXED=''}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# declare internal global variables
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
typeset -g BUFFER MATCH MBEGIN MEND CURSOR
|
|
|
|
typeset -g BUFFER MATCH MBEGIN MEND CURSOR
|
|
|
|
typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND
|
|
|
|
|
|
|
|
typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND
|
|
|
|
|
|
|
|
typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS
|
|
|
|
|
|
|
|
typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE
|
|
|
|
|
|
|
|
typeset -g _history_substring_search_refresh_display
|
|
|
|
typeset -g _history_substring_search_refresh_display
|
|
|
|
typeset -g _history_substring_search_query_highlight
|
|
|
|
typeset -g _history_substring_search_query_highlight
|
|
|
|
typeset -g _history_substring_search_result
|
|
|
|
typeset -g _history_substring_search_result
|
|
|
|
typeset -g _history_substring_search_query
|
|
|
|
typeset -g _history_substring_search_query
|
|
|
|
typeset -g -A _history_substring_search_raw_matches
|
|
|
|
typeset -g -a _history_substring_search_query_parts
|
|
|
|
typeset -g _history_substring_search_raw_match_index
|
|
|
|
typeset -g -a _history_substring_search_raw_matches
|
|
|
|
typeset -g -A _history_substring_search_matches
|
|
|
|
typeset -g -i _history_substring_search_raw_match_index
|
|
|
|
|
|
|
|
typeset -g -a _history_substring_search_matches
|
|
|
|
|
|
|
|
typeset -g -i _history_substring_search_match_index
|
|
|
|
typeset -g -A _history_substring_search_unique_filter
|
|
|
|
typeset -g -A _history_substring_search_unique_filter
|
|
|
|
typeset -g _history_substring_search_match_index
|
|
|
|
typeset -g -i _history_substring_search_zsh_5_9
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# configuration variables
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold'
|
|
|
|
|
|
|
|
typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold'
|
|
|
|
|
|
|
|
typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'
|
|
|
|
|
|
|
|
typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''
|
|
|
|
|
|
|
|
typeset -g _history_substring_search_{refresh_display,query_highlight,result,query,match_index,raw_match_index}
|
|
|
|
|
|
|
|
typeset -ga _history_substring_search{,_raw}_matches
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# the main ZLE widgets
|
|
|
|
# the main ZLE widgets
|
|
|
@@ -100,6 +99,11 @@ zle -N history-substring-search-down
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
zmodload -F zsh/parameter
|
|
|
|
zmodload -F zsh/parameter
|
|
|
|
|
|
|
|
autoload -Uz is-at-least
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if is-at-least 5.9 $ZSH_VERSION; then
|
|
|
|
|
|
|
|
_history_substring_search_zsh_5_9=1
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# We have to "override" some keys and widgets if the
|
|
|
|
# We have to "override" some keys and widgets if the
|
|
|
@@ -120,40 +124,81 @@ if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# The following snippet was taken from the zsh-syntax-highlighting project:
|
|
|
|
# Check if $1 denotes the name of a callable function, i.e. it is fully
|
|
|
|
|
|
|
|
# defined or it is marked for autoloading and autoloading it at the first
|
|
|
|
|
|
|
|
# call to it will succeed. In particular, if $1 has been marked for
|
|
|
|
|
|
|
|
# autoloading but is not available in $fpath, then it will return 1 (false).
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
# This is based on the zsh-syntax-highlighting plugin.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
_history-substring-search-function-callable() {
|
|
|
|
|
|
|
|
if (( ${+functions[$1]} )) && ! [[ "$functions[$1]" == *"builtin autoload -X"* ]]; then
|
|
|
|
|
|
|
|
return 0 # already fully loaded
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
# "$1" is either an autoload stub, or not a function at all.
|
|
|
|
|
|
|
|
# We expect 'autoload +X' to return non-zero if it fails to fully load
|
|
|
|
|
|
|
|
# the function.
|
|
|
|
|
|
|
|
( autoload -U +X -- "$1" 2>/dev/null )
|
|
|
|
|
|
|
|
return $?
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# The zsh-syntax-highlighting plugin uses zle-line-pre-redraw hook instead
|
|
|
|
|
|
|
|
# of the legacy "bind all widgets" if 1) zsh has the memo= feature (added in
|
|
|
|
|
|
|
|
# version 5.9) and 2) add-zle-hook-widget is available.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
if [[ $_history_substring_search_zsh_5_9 -eq 1 ]] && _history-substring-search-function-callable add-zle-hook-widget; then
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# The following code is based on the zsh-syntax-highlighting plugin.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
autoload -U add-zle-hook-widget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_history-substring-search-zle-line-finish() {
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Reset $WIDGET since the 'main' highlighter depends on it.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Since $WIDGET is declared by zle as read-only in this function's scope,
|
|
|
|
|
|
|
|
# a nested function is required in order to shadow its built-in value;
|
|
|
|
|
|
|
|
# see "User-defined widgets" in zshall.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
() {
|
|
|
|
|
|
|
|
local -h -r WIDGET=zle-line-finish
|
|
|
|
|
|
|
|
_zsh_highlight
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_history-substring-search-zle-line-pre-redraw() {
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# If the zsh-syntax-highlighting plugin has been loaded (after our plugin
|
|
|
|
|
|
|
|
# plugin, otherwise this hook wouldn't be called), remove our hooks.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
if [[ $+ZSH_HIGHLIGHT_VERSION -eq 1 ]]; then
|
|
|
|
|
|
|
|
autoload -U add-zle-hook-widget
|
|
|
|
|
|
|
|
add-zle-hook-widget -d zle-line-pre-redraw _history-substring-search-zle-line-pre-redraw
|
|
|
|
|
|
|
|
add-zle-hook-widget -d zle-line-finish _history-substring-search-zle-line-finish
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Set $? to 0 for _zsh_highlight. Without this, subsequent
|
|
|
|
|
|
|
|
# zle-line-pre-redraw hooks won't run, since add-zle-hook-widget happens to
|
|
|
|
|
|
|
|
# call us with $? == 1 in the common case.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
true && _zsh_highlight "$@"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ -o zle ]]; then
|
|
|
|
|
|
|
|
add-zle-hook-widget zle-line-pre-redraw _history-substring-search-zle-line-pre-redraw
|
|
|
|
|
|
|
|
add-zle-hook-widget zle-line-finish _history-substring-search-zle-line-finish
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# The following snippet was taken from the zsh-syntax-highlighting project:
|
|
|
|
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161
|
|
|
|
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
|
|
|
|
# SPDX-SnippetBegin
|
|
|
|
# All rights reserved.
|
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
#
|
|
|
|
# SPDX-SnippetCopyrightText: 2010-2011 zsh-syntax-highlighting contributors
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
|
|
|
|
# met:
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# * Neither the name of the zsh-syntax-highlighting contributors nor the
|
|
|
|
|
|
|
|
# names of its contributors may be used to endorse or promote products
|
|
|
|
|
|
|
|
# derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
|
|
|
|
|
|
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
|
|
|
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
|
|
|
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
|
|
|
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
|
|
|
|
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
|
|
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
|
|
|
|
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
|
|
|
|
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
|
|
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
|
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#--------------8<-------------------8<-------------------8<-----------------
|
|
|
|
#--------------8<-------------------8<-------------------8<-----------------
|
|
|
|
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
|
|
|
|
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
|
|
|
|
_zsh_highlight_bind_widgets()
|
|
|
|
_zsh_highlight_bind_widgets()
|
|
|
@@ -192,10 +237,14 @@ if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#-------------->8------------------->8------------------->8-----------------
|
|
|
|
#-------------->8------------------->8------------------->8-----------------
|
|
|
|
|
|
|
|
# SPDX-SnippetEnd
|
|
|
|
|
|
|
|
|
|
|
|
_zsh_highlight_bind_widgets
|
|
|
|
_zsh_highlight_bind_widgets
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unfunction _history-substring-search-function-callable
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
_history-substring-search-begin() {
|
|
|
|
_history-substring-search-begin() {
|
|
|
|
setopt localoptions extendedglob
|
|
|
|
setopt localoptions extendedglob
|
|
|
|
|
|
|
|
|
|
|
@@ -223,6 +272,7 @@ _history-substring-search-begin() {
|
|
|
|
# speed things up a little.
|
|
|
|
# speed things up a little.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
_history_substring_search_query=
|
|
|
|
_history_substring_search_query=
|
|
|
|
|
|
|
|
_history_substring_search_query_parts=()
|
|
|
|
_history_substring_search_raw_matches=()
|
|
|
|
_history_substring_search_raw_matches=()
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
@@ -233,20 +283,38 @@ _history-substring-search-begin() {
|
|
|
|
_history_substring_search_query=$BUFFER
|
|
|
|
_history_substring_search_query=$BUFFER
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# $BUFFER contains the text that is in the command-line currently.
|
|
|
|
# compose search pattern
|
|
|
|
# we put an extra "\\" before meta characters such as "\(" and "\)",
|
|
|
|
|
|
|
|
# so that they become "\\\(" and "\\\)".
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
local escaped_query=${BUFFER//(#m)[\][()|\\*?#<>~^]/\\$MATCH}
|
|
|
|
if [[ -n $HISTORY_SUBSTRING_SEARCH_FUZZY ]]; then
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# `=` split string in arguments
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
_history_substring_search_query_parts=(${=_history_substring_search_query})
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
_history_substring_search_query_parts=(${==_history_substring_search_query})
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Find all occurrences of the search query in the history file.
|
|
|
|
# Escape and join query parts with wildcard character '*' as seperator
|
|
|
|
|
|
|
|
# `(j:CHAR:)` join array to string with CHAR as seperator
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Support anchoring history search to the beginning of the command
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
if [[ -z $HISTORY_SUBSTRING_SEARCH_PREFIXED ]]; then
|
|
|
|
|
|
|
|
search_pattern="*${search_pattern}"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Find all occurrences of the search pattern in the history file.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# (k) returns the "keys" (history index numbers) instead of the values
|
|
|
|
# (k) returns the "keys" (history index numbers) instead of the values
|
|
|
|
# (R) returns values in reverse older, so the index of the youngest
|
|
|
|
# (R) returns values in reverse older, so the index of the youngest
|
|
|
|
# matching history entry is at the head of the list.
|
|
|
|
# matching history entry is at the head of the list.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
_history_substring_search_raw_matches=(${(k)history[(R)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)*${escaped_query}*]})
|
|
|
|
_history_substring_search_raw_matches=(${(k)history[(R)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)${search_pattern}]})
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
@@ -265,8 +333,7 @@ _history-substring-search-begin() {
|
|
|
|
#
|
|
|
|
#
|
|
|
|
_history_substring_search_raw_match_index=0
|
|
|
|
_history_substring_search_raw_match_index=0
|
|
|
|
_history_substring_search_matches=()
|
|
|
|
_history_substring_search_matches=()
|
|
|
|
unset _history_substring_search_unique_filter
|
|
|
|
_history_substring_search_unique_filter=()
|
|
|
|
typeset -A -g _history_substring_search_unique_filter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# If $_history_substring_search_match_index is equal to
|
|
|
|
# If $_history_substring_search_match_index is equal to
|
|
|
@@ -296,12 +363,21 @@ _history-substring-search-begin() {
|
|
|
|
_history-substring-search-end() {
|
|
|
|
_history-substring-search-end() {
|
|
|
|
setopt localoptions extendedglob
|
|
|
|
setopt localoptions extendedglob
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local highlight_memo=
|
|
|
|
_history_substring_search_result=$BUFFER
|
|
|
|
_history_substring_search_result=$BUFFER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ $_history_substring_search_zsh_5_9 -eq 1 ]]; then
|
|
|
|
|
|
|
|
highlight_memo='memo=history-substring-search'
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# the search was successful so display the result properly by clearing away
|
|
|
|
# the search was successful so display the result properly by clearing away
|
|
|
|
# existing highlights and moving the cursor to the end of the result buffer
|
|
|
|
# existing highlights and moving the cursor to the end of the result buffer
|
|
|
|
if [[ $_history_substring_search_refresh_display -eq 1 ]]; then
|
|
|
|
if [[ $_history_substring_search_refresh_display -eq 1 ]]; then
|
|
|
|
|
|
|
|
if [[ -n $highlight_memo ]]; then
|
|
|
|
|
|
|
|
region_highlight=( "${(@)region_highlight:#*${highlight_memo}*}" )
|
|
|
|
|
|
|
|
else
|
|
|
|
region_highlight=()
|
|
|
|
region_highlight=()
|
|
|
|
|
|
|
|
fi
|
|
|
|
CURSOR=${#BUFFER}
|
|
|
|
CURSOR=${#BUFFER}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
@@ -309,16 +385,23 @@ _history-substring-search-end() {
|
|
|
|
_zsh_highlight
|
|
|
|
_zsh_highlight
|
|
|
|
|
|
|
|
|
|
|
|
# highlight the search query inside the command line
|
|
|
|
# highlight the search query inside the command line
|
|
|
|
if [[ -n $_history_substring_search_query_highlight && -n $_history_substring_search_query ]]; then
|
|
|
|
if [[ -n $_history_substring_search_query_highlight ]]; then
|
|
|
|
#
|
|
|
|
# highlight first matching query parts
|
|
|
|
# The following expression yields a variable $MBEGIN, which
|
|
|
|
local highlight_start_index=0
|
|
|
|
# indicates the begin position + 1 of the first occurrence
|
|
|
|
local highlight_end_index=0
|
|
|
|
# of _history_substring_search_query in $BUFFER.
|
|
|
|
local query_part
|
|
|
|
#
|
|
|
|
for query_part in $_history_substring_search_query_parts; do
|
|
|
|
: ${(S)BUFFER##(#m$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)($_history_substring_search_query##)}
|
|
|
|
local escaped_query_part=${query_part//(#m)[\][()|\\*?#<>~^]/\\$MATCH}
|
|
|
|
local begin=$(( MBEGIN - 1 ))
|
|
|
|
# (i) get index of pattern
|
|
|
|
local end=$(( begin + $#_history_substring_search_query ))
|
|
|
|
local query_part_match_index="${${BUFFER:$highlight_start_index}[(i)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)${escaped_query_part}]}"
|
|
|
|
region_highlight+=("$begin $end $_history_substring_search_query_highlight")
|
|
|
|
if [[ $query_part_match_index -le ${#BUFFER:$highlight_start_index} ]]; then
|
|
|
|
|
|
|
|
highlight_start_index=$(( $highlight_start_index + $query_part_match_index ))
|
|
|
|
|
|
|
|
highlight_end_index=$(( $highlight_start_index + ${#query_part} ))
|
|
|
|
|
|
|
|
region_highlight+=(
|
|
|
|
|
|
|
|
"$(($highlight_start_index - 1)) $(($highlight_end_index - 1)) ${_history_substring_search_query_highlight}${highlight_memo:+,$highlight_memo}"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# For debugging purposes:
|
|
|
|
# For debugging purposes:
|
|
|
@@ -447,7 +530,7 @@ _history_substring_search_process_raw_matches() {
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Move on to the next raw entry and get its history index.
|
|
|
|
# Move on to the next raw entry and get its history index.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
(( _history_substring_search_raw_match_index++ ))
|
|
|
|
_history_substring_search_raw_match_index+=1
|
|
|
|
local index=${_history_substring_search_raw_matches[$_history_substring_search_raw_match_index]}
|
|
|
|
local index=${_history_substring_search_raw_matches[$_history_substring_search_raw_match_index]}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
@@ -627,7 +710,7 @@ _history-substring-search-up-search() {
|
|
|
|
# 1. Move index to point to the next match.
|
|
|
|
# 1. Move index to point to the next match.
|
|
|
|
# 2. Update display to indicate search found.
|
|
|
|
# 2. Update display to indicate search found.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
(( _history_substring_search_match_index++ ))
|
|
|
|
_history_substring_search_match_index+=1
|
|
|
|
_history-substring-search-found
|
|
|
|
_history-substring-search-found
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
@@ -638,7 +721,7 @@ _history-substring-search-up-search() {
|
|
|
|
# _history_substring_search_matches.
|
|
|
|
# _history_substring_search_matches.
|
|
|
|
# 2. Update display to indicate search not found.
|
|
|
|
# 2. Update display to indicate search not found.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
(( _history_substring_search_match_index++ ))
|
|
|
|
_history_substring_search_match_index+=1
|
|
|
|
_history-substring-search-not-found
|
|
|
|
_history-substring-search-not-found
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
@@ -707,7 +790,7 @@ _history-substring-search-down-search() {
|
|
|
|
# 1. Move index to point to the previous match.
|
|
|
|
# 1. Move index to point to the previous match.
|
|
|
|
# 2. Update display to indicate search found.
|
|
|
|
# 2. Update display to indicate search found.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
(( _history_substring_search_match_index-- ))
|
|
|
|
_history_substring_search_match_index+=-1
|
|
|
|
_history-substring-search-found
|
|
|
|
_history-substring-search-found
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
@@ -718,7 +801,7 @@ _history-substring-search-down-search() {
|
|
|
|
# _history_substring_search_matches.
|
|
|
|
# _history_substring_search_matches.
|
|
|
|
# 2. Update display to indicate search not found.
|
|
|
|
# 2. Update display to indicate search not found.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
(( _history_substring_search_match_index-- ))
|
|
|
|
_history_substring_search_match_index+=-1
|
|
|
|
_history-substring-search-not-found
|
|
|
|
_history-substring-search-not-found
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|