update predefined strategy and allow user set ZSH_AUTOSUGGEST_STRATEGY before plugin initializing
This commit is contained in:
		
							parent
							
								
									650aad5f08
								
							
						
					
					
						commit
						270d988ae6
					
				|  | @ -107,6 +107,7 @@ Set `ZSH_AUTOSUGGEST_STRATEGY` to choose the strategy for generating suggestions | |||
| 
 | ||||
| - `default`: Chooses the most recent match. | ||||
| - `match_prev_cmd`: Chooses the most recent match whose preceding history item matches the most recently executed command ([more info](src/strategies/match_prev_cmd.zsh)). Note that this strategy won't work as expected with ZSH options that don't preserve the history order such as `HIST_IGNORE_ALL_DUPS` or `HIST_EXPIRE_DUPS_FIRST`. | ||||
| - `predefined`: Chooses the most recent match in history and predefined database which is generated from available commands in $PATH and their help at the first time `predefined` strategy is used. | ||||
| 
 | ||||
| 
 | ||||
| ### Widget Mapping | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' | |||
| # Prefix to use when saving original versions of bound widgets | ||||
| ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- | ||||
| 
 | ||||
| ZSH_AUTOSUGGEST_STRATEGY=default | ||||
| ZSH_AUTOSUGGEST_STRATEGY=${ZSH_AUTOSUGGEST_STRATEGY:-default} | ||||
| 
 | ||||
| # Widgets that clear the suggestion | ||||
| ZSH_AUTOSUGGEST_CLEAR_WIDGETS=( | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ _zsh_autosuggest_predefined_generate() { | |||
|     # skip when ~/.zsh_autosuggest exists | ||||
|     [ -f "$pname" ] && return | ||||
| 
 | ||||
|     echo "autosuggestions is generating: $pname" | ||||
|     # echo "autosuggestions is generating: $pname" | ||||
| 
 | ||||
|     # copy builtin predefine database | ||||
|     local txt="${_zsh_autosuggest_script_path}/predefined.txt" | ||||
|  | @ -76,10 +76,15 @@ _zsh_autosuggest_strategy_predefined() { | |||
|     # search the history at first | ||||
|     local result="${history[(r)${prefix}*]}" | ||||
| 
 | ||||
|     # check if necessary to generate predefine database | ||||
|     if (( ! ${+_ZSH_AUTOSUGGEST_GENERATED} )); then | ||||
|         _ZSH_AUTOSUGGEST_GENERATED=1 | ||||
|         _zsh_autosuggest_predefined_generate | ||||
|     fi | ||||
| 
 | ||||
|     # search the predefine files if nothing found in history | ||||
|     if [[ -z "$result" ]]; then | ||||
|         if (( ! ${+_ZSH_AUTOSUGGEST_PREDEFINE} )); then | ||||
|             # _zsh_autosuggest_predefined_generate | ||||
|             typeset -g _ZSH_AUTOSUGGEST_PREDEFINE=() | ||||
|             local pbase="$_zsh_autosuggest_data_home" | ||||
|             local pname="$pbase/predefined" | ||||
|  | @ -100,7 +105,7 @@ _zsh_autosuggest_strategy_predefined() { | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| _zsh_autosuggest_predefined_generate | ||||
| # _zsh_autosuggest_predefined_generate | ||||
| 
 | ||||
| #  vim: set ts=4 sw=4 tw=0 et : | ||||
| 
 | ||||
|  |  | |||
|  | @ -593,7 +593,7 @@ _zsh_autosuggest_predefined_generate() { | |||
|     # skip when ~/.zsh_autosuggest exists | ||||
|     [ -f "$pname" ] && return | ||||
| 
 | ||||
|     echo "autosuggestions is generating: $pname" | ||||
|     # echo "autosuggestions is generating: $pname" | ||||
| 
 | ||||
|     # copy builtin predefine database | ||||
|     local txt="${_zsh_autosuggest_script_path}/predefined.txt" | ||||
|  | @ -642,10 +642,15 @@ _zsh_autosuggest_strategy_predefined() { | |||
|     # search the history at first | ||||
|     local result="${history[(r)${prefix}*]}" | ||||
| 
 | ||||
|     # check if necessary to generate predefine database | ||||
|     if (( ! ${+_ZSH_AUTOSUGGEST_GENERATED} )); then | ||||
|         _ZSH_AUTOSUGGEST_GENERATED=1 | ||||
|         _zsh_autosuggest_predefined_generate | ||||
|     fi | ||||
| 
 | ||||
|     # search the predefine files if nothing found in history | ||||
|     if [[ -z "$result" ]]; then | ||||
|         if (( ! ${+_ZSH_AUTOSUGGEST_PREDEFINE} )); then | ||||
|             # _zsh_autosuggest_predefined_generate | ||||
|             typeset -g _ZSH_AUTOSUGGEST_PREDEFINE=() | ||||
|             local pbase="$_zsh_autosuggest_data_home" | ||||
|             local pname="$pbase/predefined" | ||||
|  | @ -666,7 +671,7 @@ _zsh_autosuggest_strategy_predefined() { | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| _zsh_autosuggest_predefined_generate | ||||
| # _zsh_autosuggest_predefined_generate | ||||
| 
 | ||||
| #  vim: set ts=4 sw=4 tw=0 et : | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue