Commit 841d2b92 authored by Robby Russell's avatar Robby Russell
Browse files

Merge pull request #5053 from psprint/master

znt: update to v2.1.15
parents 5b9c6c15 e2d157d5
......@@ -14,6 +14,52 @@ _nlist_compute_first_to_show_idx() {
from_what_idx_list_is_shown=0+((current_idx-1)/page_height)*page_height+1
}
_nlist_update_from_keywords() {
keywordisfresh="1"
if [ "$nkeywords" -gt 0 ]; then
curkeyword=$(( (curkeyword+1) % (nkeywords+1) ))
if [ "$curkeyword" -eq "0" ]; then
buffer=""
else
buffer="${keywords[curkeyword]}"
fi
fi
}
_nlist_iterate_theme() {
themeisfresh="1"
if [ "$1" = "1" ]; then
curtheme=$(( (curtheme+1) % (nthemes+1) ))
else
curtheme=curtheme-1
[ "$curtheme" -lt 0 ] && curtheme=nthemes
fi
if [ "$nthemes" -gt 0 ]; then
local theme=${themes[curtheme]}
[ "$curtheme" -eq "0" ] && theme="$backuptheme"
colorpair="${theme%/*}"
bold="${theme##*/}"
background="${colorpair#*/}"
zcurses bg main "$colorpair"
zcurses bg inner "$colorpair"
fi
}
_nlist_rotate_buffer() {
setopt localoptions noglob
local -a words
words=( ${(s: :)buffer} )
words=( ${words[-1]} ${words[1,-2]} )
local space=""
[ "${buffer[-1]}" = " " ] && space=" "
buffer="${(j: :)words}$space"
}
typeset -ga reply
reply=( -1 '' )
integer current_idx="$1"
......@@ -26,6 +72,7 @@ local key="$7"
integer search="$8"
local buffer="$9"
integer uniq_mode="$10"
integer f_mode="$11"
#
# Listening for input
......@@ -79,21 +126,36 @@ case "$key" in
${NLIST_NONSELECTABLE_ELEMENTS[(r)$current_idx]} != $current_idx ]]
then
# Save current element in the result variable
reply=( $current_idx SELECT )
reply=( $current_idx "SELECT" )
fi
;;
(H|'?')
# This event needs to be enabled
if [[ "${NLIST_ENABLED_EVENTS[(r)HELP]}" = "HELP" ]]; then
reply=( -1 "HELP" )
fi
;;
(F1)
# This event needs to be enabled
if [[ "${NLIST_ENABLED_EVENTS[(r)F1]}" = "F1" ]]; then
reply=( -1 "$key" )
fi
;;
(F4|F5|F6|F7|F8|F9|F10|DC)
# ignore; F2, F3 are used below
;;
(q)
reply=( -1 QUIT )
reply=( -1 "QUIT" )
;;
(/)
search=1
_nlist_cursor_visibility 1
;;
($'\t')
reply=( $current_idx LEAVE )
reply=( $current_idx "LEAVE" )
;;
($'\C-L')
reply=( -1 REDRAW )
reply=( -1 "REDRAW" )
;;
(\])
[[ "${(t)NLIST_HOP_INDEXES}" = "array" || "${(t)NLIST_HOP_INDEXES}" = "array-local" ]] &&
......@@ -127,9 +189,41 @@ case "$key" in
($'\E')
buffer=""
;;
(F3)
if [ "$search" = "1" ]; then
search=0
_nlist_cursor_visibility 0
else
search=1
_nlist_cursor_visibility 1
fi
;;
(o|$'\C-O')
uniq_mode=1-uniq_mode
;;
(f|$'\C-F')
(( f_mode=(f_mode+1) % 3 ))
;;
($'\x1F'|F2|$'\C-X')
search=1
_nlist_cursor_visibility 1
_nlist_update_from_keywords
;;
($'\C-T')
_nlist_iterate_theme 1
;;
($'\C-G')
_nlist_iterate_theme 0
;;
($'\C-E'|e)
# This event needs to be enabled
if [[ "${NLIST_ENABLED_EVENTS[(r)EDIT]}" = "EDIT" ]]; then
reply=( -1 "EDIT" )
fi
;;
($'\C-A')
_nlist_rotate_buffer
;;
(*)
;;
esac
......@@ -138,11 +232,19 @@ else
case "$key" in
($'\n'|ENTER)
search=0
_nlist_cursor_visibility 0
if [ "$NLIST_INSTANT_SELECT" = "1" ]; then
if [[ "$NLIST_SEARCH_BUFFER" != "" || "$NLIST_IS_UNIQ_MODE" -eq 1 ||
${NLIST_NONSELECTABLE_ELEMENTS[(r)$current_idx]} != $current_idx ]]
then
reply=( $current_idx "SELECT" )
fi
else
search=0
_nlist_cursor_visibility 0
fi
;;
($'\C-L')
reply=( -1 REDRAW )
reply=( -1 "REDRAW" )
;;
#
......@@ -192,8 +294,14 @@ case "$key" in
(RIGHT)
hscroll+=7
;;
(F1|F2|F3|F4|F5|F6|F7|F8|F9|F10)
# ignore
(F1)
# This event needs to be enabled
if [[ "${NLIST_ENABLED_EVENTS[(r)F1]}" = "F1" ]]; then
reply=( -1 "$key" )
fi
;;
(F4|F5|F6|F7|F8|F9|F10|DC)
# ignore; F2, F3 are used below
;;
#
......@@ -214,9 +322,39 @@ case "$key" in
search=0
_nlist_cursor_visibility 0
;;
(F3)
if [ "$search" = "1" ]; then
search=0
_nlist_cursor_visibility 0
else
search=1
_nlist_cursor_visibility 1
fi
;;
($'\C-O')
uniq_mode=1-uniq_mode
;;
($'\C-F')
(( f_mode=(f_mode+1) % 3 ))
;;
($'\x1F'|F2|$'\C-X')
_nlist_update_from_keywords
;;
($'\C-T')
_nlist_iterate_theme 1
;;
($'\C-G')
_nlist_iterate_theme 0
;;
($'\C-E')
# This event needs to be enabled
if [[ "${NLIST_ENABLED_EVENTS[(r)EDIT]}" = "EDIT" ]]; then
reply=( -1 "EDIT" )
fi
;;
($'\C-A')
_nlist_rotate_buffer
;;
(*)
if [[ $#key == 1 && $((#key)) -lt 31 ]]; then
# ignore all other control keys
......@@ -234,5 +372,6 @@ reply[5]="$hscroll"
reply[6]="$search"
reply[7]="$buffer"
reply[8]="$uniq_mode"
reply[9]="$f_mode"
# vim: set filetype=zsh:
......@@ -14,8 +14,8 @@ local IFS="
unset NLIST_COLORING_PATTERN
[ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf
[ -f ~/.config/znt/n-options.conf ] && . ~/.config/znt/n-options.conf
[ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
[ -f ~/.config/znt/n-options.conf ] && builtin source ~/.config/znt/n-options.conf
# TODO restore options
unsetopt localoptions
......
......@@ -17,8 +17,8 @@ local IFS="
unset NLIST_COLORING_PATTERN
[ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf
[ -f ~/.config/znt/n-panelize.conf ] && . ~/.config/znt/n-panelize.conf
[ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
[ -f ~/.config/znt/n-panelize.conf ] && builtin source ~/.config/znt/n-panelize.conf
local list
local selected
......
......@@ -4,6 +4,14 @@ local NLIST_START_IN_UNIQ_MODE=1
# Only if current $BUFFER doesn't come from history
if [ "$HISTCMD" = "$HISTNO" ]; then
() {
setopt localoptions extendedglob
local -a match mbegin mend
local MATCH; integer MBEGIN MEND
[ -n "$BUFFER" ] && BUFFER="${BUFFER%% ##} "
}
local NLIST_SET_SEARCH_TO="$BUFFER"
fi
......
......@@ -15,13 +15,21 @@ if ! test -d "$CONFIG_DIR"; then
mkdir "$CONFIG_DIR"
fi
# 9 files
set n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
for i; do
if ! test -f "$CONFIG_DIR/$i"; then
cp "$REPO_DIR/.config/znt/$i" "$CONFIG_DIR"
fi
done
# Check for random 2 files if they exist
# This will shift 0 - 7 elements
shift $(( RANDOM % 8 ))
if ! test -f "$CONFIG_DIR/$1" || ! test -f "$CONFIG_DIR/$2"; then
# Something changed - examine every file
set n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
for i; do
if ! test -f "$CONFIG_DIR/$i"; then
cp "$REPO_DIR/.config/znt/$i" "$CONFIG_DIR"
fi
done
fi
# Don't leave positional parameters being set
set --
......@@ -30,12 +38,13 @@ set --
# Load functions
#
autoload n-aliases n-cd n-env n-functions n-history n-kill n-list n-list-draw n-list-input n-options n-panelize
autoload n-aliases n-cd n-env n-functions n-history n-kill n-list n-list-draw n-list-input n-options n-panelize n-help
autoload znt-usetty-wrapper znt-history-widget znt-cd-widget znt-kill-widget
alias naliases=n-aliases ncd=n-cd nenv=n-env nfunctions=n-functions nhistory=n-history
alias nkill=n-kill noptions=n-options npanelize=n-panelize
alias nkill=n-kill noptions=n-options npanelize=n-panelize nhelp=n-help
zle -N znt-history-widget
bindkey '^R' znt-history-widget
setopt AUTO_PUSHD HIST_IGNORE_DUPS PUSHD_IGNORE_DUPS
zstyle ':completion::complete:n-kill::bits' matcher 'r:|=** l:|=*'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment