Explorar el Código

Default strategy now tries history first and falls back to completion

pull/344/head
Eric Freese hace 6 años
padre
commit
c5551daabc
Se han modificado 3 ficheros con 50 adiciones y 16 borrados
  1. +7
    -15
      src/strategies/default.zsh
  2. +25
    -0
      src/strategies/history.zsh
  3. +18
    -1
      zsh-autosuggestions.zsh

+ 7
- 15
src/strategies/default.zsh Ver fichero

@ -2,24 +2,16 @@
#--------------------------------------------------------------------#
# Default Suggestion Strategy #
#--------------------------------------------------------------------#
# Suggests the most recent history item that matches the given
# prefix.
# Will provide suggestions from your history. If no matches are found
# in history, will provide a suggestion from the completion engine.
#
_zsh_autosuggest_strategy_default() {
# Reset options to defaults and enable LOCAL_OPTIONS
emulate -L zsh
typeset -g suggestion
# Enable globbing flags so that we can use (#m)
setopt EXTENDED_GLOB
_zsh_autosuggest_strategy_history "$1"
# Escape backslashes and all of the glob operators so we can use
# this string as a pattern to search the $history associative array.
# - (#m) globbing flag enables setting references for match data
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
# Get the history items that match
# - (r) subscript flag makes the pattern match on values
typeset -g suggestion="${history[(r)${prefix}*]}"
if [[ -z "$suggestion" ]]; then
_zsh_autosuggest_strategy_completion "$1"
fi
}

+ 25
- 0
src/strategies/history.zsh Ver fichero

@ -0,0 +1,25 @@
#--------------------------------------------------------------------#
# History Suggestion Strategy #
#--------------------------------------------------------------------#
# Suggests the most recent history item that matches the given
# prefix.
#
_zsh_autosuggest_strategy_history() {
# Reset options to defaults and enable LOCAL_OPTIONS
emulate -L zsh
# Enable globbing flags so that we can use (#m)
setopt EXTENDED_GLOB
# Escape backslashes and all of the glob operators so we can use
# this string as a pattern to search the $history associative array.
# - (#m) globbing flag enables setting references for match data
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
# Get the history items that match
# - (r) subscript flag makes the pattern match on values
typeset -g suggestion="${history[(r)${prefix}*]}"
}

+ 18
- 1
zsh-autosuggestions.zsh Ver fichero

@ -631,11 +631,28 @@ _zsh_autosuggest_strategy_completion() {
#--------------------------------------------------------------------#
# Default Suggestion Strategy #
#--------------------------------------------------------------------#
# Will provide suggestions from your history. If no matches are found
# in history, will provide a suggestion from the completion engine.
#
_zsh_autosuggest_strategy_default() {
typeset -g suggestion
_zsh_autosuggest_strategy_history "$1"
if [[ -z "$suggestion" ]]; then
_zsh_autosuggest_strategy_completion "$1"
fi
}
#--------------------------------------------------------------------#
# History Suggestion Strategy #
#--------------------------------------------------------------------#
# Suggests the most recent history item that matches the given
# prefix.
#
_zsh_autosuggest_strategy_default() {
_zsh_autosuggest_strategy_history() {
# Reset options to defaults and enable LOCAL_OPTIONS
emulate -L zsh

Cargando…
Cancelar
Guardar