mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-25 23:30:08 +00:00
znt: faster startup of tools using colorifying (e.g. n-history)
This commit is contained in:
parent
d427ac1ef9
commit
89205f90e5
2 changed files with 14 additions and 36 deletions
|
@ -105,8 +105,7 @@ colorize output of the tools, via their config files (check out e.g. n-cd.conf,
|
||||||
it uses this).
|
it uses this).
|
||||||
|
|
||||||
## Performance
|
## Performance
|
||||||
ZNT are fastest with Zsh before 5.0.8 and starting from 5.2 (the version yet to
|
ZNT are fastest with Zsh before 5.0.8 and starting from 5.2
|
||||||
be released).
|
|
||||||
|
|
||||||
|
|
||||||
vim:filetype=conf
|
vim:filetype=conf
|
||||||
|
|
|
@ -116,15 +116,15 @@ _nlist_setup_user_vars() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_nlist_coloring_list_into_col_list() {
|
_nlist_colorify_disp_list() {
|
||||||
local col=$'\x1b[00;34m' reset=$'\x1b[0m'
|
local col=$'\x1b[00;34m' reset=$'\x1b[0m'
|
||||||
[ -n "$NLIST_COLORING_COLOR" ] && col="$NLIST_COLORING_COLOR"
|
[ -n "$NLIST_COLORING_COLOR" ] && col="$NLIST_COLORING_COLOR"
|
||||||
[ -n "$NLIST_COLORING_END_COLOR" ] && reset="$NLIST_COLORING_END_COLOR"
|
[ -n "$NLIST_COLORING_END_COLOR" ] && reset="$NLIST_COLORING_END_COLOR"
|
||||||
|
|
||||||
if [ "$NLIST_COLORING_MATCH_MULTIPLE" -eq 1 ]; then
|
if [ "$NLIST_COLORING_MATCH_MULTIPLE" -eq 1 ]; then
|
||||||
col_list=( "${(@)list//(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
|
disp_list=( "${(@)disp_list//(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
|
||||||
else
|
else
|
||||||
col_list=( "${(@)list/(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
|
disp_list=( "${(@)disp_list/(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ integer inner_width=term_width-3
|
||||||
integer page_height=inner_height
|
integer page_height=inner_height
|
||||||
integer page_width=inner_width
|
integer page_width=inner_width
|
||||||
|
|
||||||
typeset -a list col_list disp_list
|
typeset -a list disp_list
|
||||||
integer last_element=$#
|
integer last_element=$#
|
||||||
local action
|
local action
|
||||||
local final_key
|
local final_key
|
||||||
|
@ -227,16 +227,10 @@ keypad=""
|
||||||
list=( "$@" )
|
list=( "$@" )
|
||||||
last_element="$#list"
|
last_element="$#list"
|
||||||
|
|
||||||
integer is_colored=0
|
|
||||||
if [[ -z "$NLIST_SEARCH_BUFFER" && -n "$NLIST_COLORING_PATTERN" ]]; then
|
|
||||||
is_colored=1
|
|
||||||
_nlist_coloring_list_into_col_list
|
|
||||||
fi
|
|
||||||
|
|
||||||
while (( 1 )); do
|
while (( 1 )); do
|
||||||
# Do searching (filtering with string)
|
# Do searching (filtering with string)
|
||||||
if [ -n "$NLIST_SEARCH_BUFFER" ]; then
|
if [ -n "$NLIST_SEARCH_BUFFER" ]; then
|
||||||
# Compute new list, col_list ?
|
# Compute new list?
|
||||||
if [[ "$NLIST_SEARCH_BUFFER" != "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then
|
if [[ "$NLIST_SEARCH_BUFFER" != "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then
|
||||||
prev_search_buffer="$NLIST_SEARCH_BUFFER"
|
prev_search_buffer="$NLIST_SEARCH_BUFFER"
|
||||||
prev_uniq_mode="$NLIST_IS_UNIQ_MODE"
|
prev_uniq_mode="$NLIST_IS_UNIQ_MODE"
|
||||||
|
@ -290,7 +284,7 @@ while (( 1 )); do
|
||||||
disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" )
|
disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We have display list, lets replace newlines with "\n" when needed (1/3)
|
# We have display list, lets replace newlines with "\n" when needed (1/2)
|
||||||
[ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
|
[ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -302,7 +296,7 @@ while (( 1 )); do
|
||||||
# There is no search, but there was in previous loop
|
# There is no search, but there was in previous loop
|
||||||
# OR
|
# OR
|
||||||
# Uniq mode was entered or left out
|
# Uniq mode was entered or left out
|
||||||
# -> compute new list (maybe also col_list)
|
# -> compute new list
|
||||||
if [[ -n "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then
|
if [[ -n "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then
|
||||||
prev_search_buffer=""
|
prev_search_buffer=""
|
||||||
prev_uniq_mode="$NLIST_IS_UNIQ_MODE"
|
prev_uniq_mode="$NLIST_IS_UNIQ_MODE"
|
||||||
|
@ -322,13 +316,6 @@ while (( 1 )); do
|
||||||
# Remove duplicates when in uniq mode
|
# Remove duplicates when in uniq mode
|
||||||
[ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list
|
[ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list
|
||||||
|
|
||||||
# Apply coloring pattern (when not with search query)
|
|
||||||
is_colored=0
|
|
||||||
if [ -n "$NLIST_COLORING_PATTERN" ]; then
|
|
||||||
is_colored=1
|
|
||||||
_nlist_coloring_list_into_col_list
|
|
||||||
fi
|
|
||||||
|
|
||||||
last_element="$#list"
|
last_element="$#list"
|
||||||
# Called after processing list
|
# Called after processing list
|
||||||
_nlist_verify_vars
|
_nlist_verify_vars
|
||||||
|
@ -340,23 +327,15 @@ while (( 1 )); do
|
||||||
integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 ))
|
integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 ))
|
||||||
[ "$end_idx" -gt "$last_element" ] && end_idx=last_element
|
[ "$end_idx" -gt "$last_element" ] && end_idx=last_element
|
||||||
|
|
||||||
if [ "$is_colored" -eq 0 ]; then
|
|
||||||
if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
|
if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
|
||||||
prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
|
prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
|
||||||
disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
|
disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
|
||||||
|
|
||||||
# We have display list, lets replace newlines with "\n" when needed (2/3)
|
[ -n "$NLIST_COLORING_PATTERN" ] && _nlist_colorify_disp_list
|
||||||
[ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
|
|
||||||
prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
|
|
||||||
disp_list=( "${(@)col_list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
|
|
||||||
|
|
||||||
# We have display list, lets replace newlines with "\n" when needed (3/3)
|
# We have display list, lets replace newlines with "\n" when needed (2/2)
|
||||||
[ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
|
[ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Output the list
|
# Output the list
|
||||||
n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \
|
n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \
|
||||||
|
|
Loading…
Reference in a new issue