"page-size" zstyle (:history-search-multi-word)

This commit is contained in:
Sebastian Gniazdowski 2016-05-25 09:24:03 +02:00
parent 22271dd86e
commit f632a186d7
2 changed files with 15 additions and 1 deletions

View file

@ -14,6 +14,11 @@ https://asciinema.org/a/46371
- Cooperation with
[zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions)
plugin
- Configuration option to set page size, example use:
```zsh
zstyle ":history-search-multi-word" page-size "5"
```
## Installation

View file

@ -7,6 +7,9 @@
# bindkey "^R" history-search-multi-word
#
# This will bind to Ctrl-R
#
# Example zstyles:
# zstyle ":history-search-multi-word" page-size "5"
emulate -LR zsh
setopt typesetsilent extendedglob noshortloops
@ -17,11 +20,17 @@ zmodload zsh/termcap 2>/dev/null
typeset -g __hsmw_hcw_index
typeset -g __hsmw_hcw_widget_name __hsmw_hcw_restart __hsmw_hcw_call_count
typeset -g __hsmw_page_size
typeset -gaU __hsmw_hcw_found
_hsmw_main() {
# First call or restart?
if [[ "$__hsmw_hcw_call_count" -le 1 || "$__hsmw_hcw_restart" = "1" ]]; then
if [[ "$__hsmw_hcw_call_count" -le 1 ]]; then
# Read configuration data
zstyle -s ':history-search-multi-word' page-size __hsmw_page_size || __hsmw_page_size=$(( LINES / 2 ))
fi
# '0' will get changed into $to_display limit
[[ "$WIDGET" != *-backwards ]] && __hsmw_hcw_index="1" || __hsmw_hcw_index="0"
__hsmw_hcw_widget_name="${WIDGET%-backwards}"
@ -56,7 +65,7 @@ _hsmw_main() {
# Pagination, index value guards
#
integer page_size=$(( LINES / 2 ))
integer page_size="$__hsmw_page_size"
integer max_index="$#__hsmw_hcw_found"
[ "$page_size" -gt "$max_index" ] && page_size="$max_index"
[ "$__hsmw_hcw_index" -le 0 ] && __hsmw_hcw_index="$max_index"