mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-19 20:29:45 +01:00
Merge pull request #4755 from psprint/master
znt: optimizations for zsh<=5.2
This commit is contained in:
commit
40016afdc4
7 changed files with 25 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
||||||
# Hotlist
|
# Hotlist
|
||||||
|
# Try to use $ZSH_VERSION, e.g. /usr/share/zsh/$ZSH_VERSION/functions
|
||||||
local hotlist
|
local hotlist
|
||||||
hotlist=(
|
hotlist=(
|
||||||
~/.config/znt
|
~/.config/znt
|
||||||
|
@ -7,7 +8,6 @@ hotlist=(
|
||||||
/usr/local/share/zsh/site-functions
|
/usr/local/share/zsh/site-functions
|
||||||
/usr/local/share/zsh
|
/usr/local/share/zsh
|
||||||
/usr/local/bin
|
/usr/local/bin
|
||||||
/usr/lib
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Suppress adding (to directory stack) directories visited by n-cd
|
# Suppress adding (to directory stack) directories visited by n-cd
|
||||||
|
|
|
@ -25,7 +25,7 @@ widgets exist, znt-cd-widget and znt-kill-widget, they can be too assigned
|
||||||
to key combinations (no need for autoload when using Oh My Zsh):
|
to key combinations (no need for autoload when using Oh My Zsh):
|
||||||
|
|
||||||
zle -N znt-cd-widget
|
zle -N znt-cd-widget
|
||||||
bindkey "^T" znt-cd-widget
|
bindkey "^A" znt-cd-widget
|
||||||
zle -N znt-kill-widget
|
zle -N znt-kill-widget
|
||||||
bindkey "^Y" znt-kill-widget
|
bindkey "^Y" znt-kill-widget
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ if [ "$REPLY" -gt 0 ]; then
|
||||||
# ZLE?
|
# ZLE?
|
||||||
if [ "${(t)CURSOR}" = "integer-local-special" ]; then
|
if [ "${(t)CURSOR}" = "integer-local-special" ]; then
|
||||||
zle redisplay
|
zle redisplay
|
||||||
zle kill-whole-line
|
zle kill-buffer
|
||||||
zle -U "$selected"
|
zle -U "$selected"
|
||||||
else
|
else
|
||||||
print -zr "$selected"
|
print -zr "$selected"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# $1, $2, ... - elements of the list
|
# $1, $2, ... - elements of the list
|
||||||
# $NLIST_NONSELECTABLE_ELEMENTS - array of indexes (1-based) that cannot be selected
|
# $NLIST_NONSELECTABLE_ELEMENTS - array of indexes (1-based) that cannot be selected
|
||||||
# $REPLY is the output variable - contains index (1-based) or -1 when no selection
|
# $REPLY is the output variable - contains index (1-based) or -1 when no selection
|
||||||
|
# $reply (array) is the second part of the output - use the index (REPLY) to get selected element
|
||||||
#
|
#
|
||||||
# Copy this file into /usr/share/zsh/site-functions/
|
# Copy this file into /usr/share/zsh/site-functions/
|
||||||
# and add 'autoload n-list` to .zshrc
|
# and add 'autoload n-list` to .zshrc
|
||||||
|
@ -164,6 +165,7 @@ integer current_difference=0
|
||||||
local prev_search_buffer=""
|
local prev_search_buffer=""
|
||||||
integer prev_uniq_mode=0
|
integer prev_uniq_mode=0
|
||||||
integer prev_start_idx=-1
|
integer prev_start_idx=-1
|
||||||
|
local MBEGIN MEND MATCH mbegin mend match
|
||||||
|
|
||||||
# Ability to remember the list between calls
|
# Ability to remember the list between calls
|
||||||
if [[ -z "$NLIST_REMEMBER_STATE" || "$NLIST_REMEMBER_STATE" -eq 0 || "$NLIST_REMEMBER_STATE" -eq 2 ]]; then
|
if [[ -z "$NLIST_REMEMBER_STATE" || "$NLIST_REMEMBER_STATE" -eq 0 || "$NLIST_REMEMBER_STATE" -eq 2 ]]; then
|
||||||
|
@ -264,11 +266,15 @@ while (( 1 )); do
|
||||||
local search_pattern=""
|
local search_pattern=""
|
||||||
local colsearch_pattern=""
|
local colsearch_pattern=""
|
||||||
if [ -n "$search_buffer" ]; then
|
if [ -n "$search_buffer" ]; then
|
||||||
# Patterns will be *foo*~^*bar* and foo|bar)
|
# Patterns will be *foo*~^*bar* and (foo|bar)
|
||||||
search_pattern="${search_buffer// ##/*~^*}"
|
search_pattern="${search_buffer// ##/*~^*}"
|
||||||
colsearch_pattern="${search_buffer// ##/|}"
|
colsearch_pattern="${search_buffer// ##/|}"
|
||||||
|
|
||||||
|
# The repeat will make the matching work on a fresh heap
|
||||||
|
repeat 1; do
|
||||||
list=( "${(@M)list:#(#i)*$~search_pattern*}" )
|
list=( "${(@M)list:#(#i)*$~search_pattern*}" )
|
||||||
|
done
|
||||||
|
|
||||||
last_element="$#list"
|
last_element="$#list"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -287,7 +293,10 @@ while (( 1 )); do
|
||||||
|
|
||||||
if [ -n "$colsearch_pattern" ]; then
|
if [ -n "$colsearch_pattern" ]; then
|
||||||
local red=$'\x1b[00;31m' reset=$'\x1b[00;00m'
|
local red=$'\x1b[00;31m' reset=$'\x1b[00;00m'
|
||||||
|
# The repeat will make the matching work on a fresh heap
|
||||||
|
repeat 1; do
|
||||||
disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" )
|
disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" )
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We have display list, lets replace newlines with "\n" when needed (1/2)
|
# We have display list, lets replace newlines with "\n" when needed (1/2)
|
||||||
|
|
|
@ -98,7 +98,7 @@ shift 7
|
||||||
integer max_text_len=page_width-x_offset
|
integer max_text_len=page_width-x_offset
|
||||||
|
|
||||||
[ "$bold" = "0" ] && bold="" || bold="+bold"
|
[ "$bold" = "0" ] && bold="" || bold="+bold"
|
||||||
[[ "$active_text" = "underline" || "$active_text" = "reverse" ]] || active_text="reverse"
|
[[ "$active_text" = "underline" || "$active_text" = "reverse" ]] || local active_text="reverse"
|
||||||
# With Linux terminal underline won't work properly
|
# With Linux terminal underline won't work properly
|
||||||
[ "$TERM" = "linux" ] && active_text="reverse"
|
[ "$TERM" = "linux" ] && active_text="reverse"
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ case "$key" in
|
||||||
[ "$current_idx" -lt "$last_element" ] && current_idx=current_idx+1;
|
[ "$current_idx" -lt "$last_element" ] && current_idx=current_idx+1;
|
||||||
_nlist_compute_first_to_show_idx
|
_nlist_compute_first_to_show_idx
|
||||||
;;
|
;;
|
||||||
(PPAGE)
|
(PPAGE|$'\b'|$'\C-?'|BACKSPACE)
|
||||||
current_idx=current_idx-page_height
|
current_idx=current_idx-page_height
|
||||||
[ "$current_idx" -lt 1 ] && current_idx=1;
|
[ "$current_idx" -lt 1 ] && current_idx=1;
|
||||||
_nlist_compute_first_to_show_idx
|
_nlist_compute_first_to_show_idx
|
||||||
|
@ -72,7 +72,7 @@ case "$key" in
|
||||||
current_idx=last_element
|
current_idx=last_element
|
||||||
_nlist_compute_first_to_show_idx
|
_nlist_compute_first_to_show_idx
|
||||||
;;
|
;;
|
||||||
($'\n')
|
($'\n'|ENTER)
|
||||||
# Is that element selectable?
|
# Is that element selectable?
|
||||||
# Check for this only when there is no search
|
# Check for this only when there is no search
|
||||||
if [[ "$NLIST_SEARCH_BUFFER" != "" || "$NLIST_IS_UNIQ_MODE" -eq 1 ||
|
if [[ "$NLIST_SEARCH_BUFFER" != "" || "$NLIST_IS_UNIQ_MODE" -eq 1 ||
|
||||||
|
@ -137,7 +137,7 @@ esac
|
||||||
else
|
else
|
||||||
|
|
||||||
case "$key" in
|
case "$key" in
|
||||||
($'\n')
|
($'\n'|ENTER)
|
||||||
search=0
|
search=0
|
||||||
_nlist_cursor_visibility 0
|
_nlist_cursor_visibility 0
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
autoload znt-usetty-wrapper n-history
|
autoload znt-usetty-wrapper n-history
|
||||||
local NLIST_START_IN_SEARCH_MODE=1
|
local NLIST_START_IN_SEARCH_MODE=1
|
||||||
local NLIST_START_IN_UNIQ_MODE=1
|
local NLIST_START_IN_UNIQ_MODE=1
|
||||||
|
|
||||||
|
# Only if current $BUFFER doesn't come from history
|
||||||
|
if [ "$HISTCMD" = "$HISTNO" ]; then
|
||||||
local NLIST_SET_SEARCH_TO="$BUFFER"
|
local NLIST_SET_SEARCH_TO="$BUFFER"
|
||||||
|
fi
|
||||||
|
|
||||||
znt-usetty-wrapper n-history "$@"
|
znt-usetty-wrapper n-history "$@"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue