c82f49e734973debfcab9dd7f1a76bfd42186880

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Merge pull request #4652 from psprint/master

znt: updated README.md, twice as fast searching

Diff

 1diff --git a/plugins/zsh-navigation-tools/README.md b/plugins/zsh-navigation-tools/README.md
 2index 686213c36836c7a5aff8257ab8cd5849b57f23e5..670a85ece9f073d70ed4df1f1f13860ac02ac71c 100644
 3--- a/plugins/zsh-navigation-tools/README.md
 4+++ b/plugins/zsh-navigation-tools/README.md
 5@@ -105,7 +105,8 @@ colorize output of the tools, via their config files (check out e.g. n-cd.conf,
 6 it uses this).
 7 
 8 ## Performance
 9-ZNT is fastest with Zsh before 5.0.8 and starting from 5.2 (the version yet to
10+ZNT are fastest with Zsh before 5.0.8 and starting from 5.2 (the version yet to
11 be released).
12 
13-# vim:filetype=conf
14+
15+vim:filetype=conf
16diff --git a/plugins/zsh-navigation-tools/n-list b/plugins/zsh-navigation-tools/n-list
17index c7066318edf58291d60ec791410eaa80081aadb1..26431a0d9c24ce581c2abda128c75a3e8a3da406 100644
18--- a/plugins/zsh-navigation-tools/n-list
19+++ b/plugins/zsh-navigation-tools/n-list
20@@ -261,18 +261,15 @@ while (( 1 )); do
21             local search_buffer="${NLIST_SEARCH_BUFFER%% ##}"
22             search_buffer="${search_buffer## ##}"
23             search_buffer="${search_buffer//(#m)[][*?|#~^()><\\]/\\$MATCH}"
24+            local search_pattern=""
25+            local colsearch_pattern=""
26             if [ -n "$search_buffer" ]; then
27                 # Patterns will be *foo*~^*bar* and foo|bar)
28-                local search_pattern="${search_buffer// ##/*~^*}"
29-                local colsearch_pattern="${search_buffer// ##/|}"
30+                search_pattern="${search_buffer// ##/*~^*}"
31+                colsearch_pattern="${search_buffer// ##/|}"
32 
33                 list=( "${(@M)list:#(#i)*$~search_pattern*}" )
34                 last_element="$#list"
35-
36-                local red=$'\x1b[00;31m' reset=$'\x1b[00;00m'
37-                col_list=( "${(@)list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" )
38-            else
39-                col_list=( "$list[@]" )
40             fi
41 
42             # Called after processing list
43@@ -286,7 +283,12 @@ while (( 1 )); do
44 
45         if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
46             prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
47-            disp_list=( "${(@)col_list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
48+            disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
49+
50+            if [ -n "$colsearch_pattern" ]; then
51+                local red=$'\x1b[00;31m' reset=$'\x1b[00;00m'
52+                disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" )
53+            fi
54 
55             # We have display list, lets replace newlines with "\n" when needed (1/3)
56             [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )