update predefined strategies

This commit is contained in:
skywind3000 2018-03-07 16:43:47 +08:00
parent 942662d12d
commit 050143d539
2 changed files with 46 additions and 44 deletions

View file

@ -27,7 +27,7 @@ _zsh_autosuggest_predefined_generate() {
# skip when ~/.zsh_autosuggest exists # skip when ~/.zsh_autosuggest exists
[ -f "$pname" ] && return [ -f "$pname" ] && return
# echo "autosuggestions is generating: $pname" echo "autosuggestions is generating: $pname"
# copy builtin predefine database # copy builtin predefine database
local txt="${_zsh_autosuggest_script_path}/predefined.txt" local txt="${_zsh_autosuggest_script_path}/predefined.txt"
@ -36,25 +36,26 @@ _zsh_autosuggest_predefined_generate() {
# enumerate commands in $PATH and add them to ~/.zsh_autosuggest # enumerate commands in $PATH and add them to ~/.zsh_autosuggest
for p ("${(@s/:/)PATH}"); do for p ("${(@s/:/)PATH}"); do
cd "$p" [ ! -d "$p" ] && continue
local files=("${(@f)$(ls -la | awk -F ' ' '{print $9}')}") cd "$p"
for fn in ${files}; do local files=("${(@f)$(ls -la | awk -F ' ' '{print $9}')}")
if [ -x "$fn" ] && [[ "${fn:l}" != *.dll ]]; then for fn in ${files}; do
if [ -f "$fn" ] && [[ "${fn:l}" != *.nls ]]; then if [ -x "$fn" ] && [[ "${fn:l}" != *.dll ]]; then
# trim cygwin .exe/.cmd/.bat postfix if [ -f "$fn" ] && [[ "${fn:l}" != *.nls ]]; then
if [[ "$fn" == *.exe ]]; then # trim cygwin .exe/.cmd/.bat postfix
fn=${fn/%.exe/} if [[ "$fn" == *.exe ]]; then
elif [[ "$fn" == *.cmd ]]; then fn=${fn/%.exe/}
fn=${fn/%.cmd/} elif [[ "$fn" == *.cmd ]]; then
elif [[ "$fn" == *.bat ]]; then fn=${fn/%.cmd/}
fn=${fn/%.bat/} elif [[ "$fn" == *.bat ]]; then
fi fn=${fn/%.bat/}
if [[ ${#fn} -gt 1 ]]; then fi
suggests+=$fn if [[ ${#fn} -gt 1 ]]; then
fi suggests+=$fn
fi fi
fi fi
done fi
done
done done
cd "${pwd}" cd "${pwd}"
@ -78,7 +79,7 @@ _zsh_autosuggest_strategy_predefined() {
# search the predefine files if nothing found in history # search the predefine files if nothing found in history
if [[ -z "$result" ]]; then if [[ -z "$result" ]]; then
if (( ! ${+_ZSH_AUTOSUGGEST_PREDEFINE} )); then if (( ! ${+_ZSH_AUTOSUGGEST_PREDEFINE} )); then
_zsh_autosuggest_predefined_generate # _zsh_autosuggest_predefined_generate
typeset -g _ZSH_AUTOSUGGEST_PREDEFINE=() typeset -g _ZSH_AUTOSUGGEST_PREDEFINE=()
local pbase="$_zsh_autosuggest_data_home" local pbase="$_zsh_autosuggest_data_home"
local pname="$pbase/predefined" local pname="$pbase/predefined"
@ -99,7 +100,7 @@ _zsh_autosuggest_strategy_predefined() {
} }
# _zsh_autosuggest_predefined_generate _zsh_autosuggest_predefined_generate
# vim: set ts=4 sw=4 tw=0 noet : # vim: set ts=4 sw=4 tw=0 noet :

View file

@ -593,7 +593,7 @@ _zsh_autosuggest_predefined_generate() {
# skip when ~/.zsh_autosuggest exists # skip when ~/.zsh_autosuggest exists
[ -f "$pname" ] && return [ -f "$pname" ] && return
# echo "autosuggestions is generating: $pname" echo "autosuggestions is generating: $pname"
# copy builtin predefine database # copy builtin predefine database
local txt="${_zsh_autosuggest_script_path}/predefined.txt" local txt="${_zsh_autosuggest_script_path}/predefined.txt"
@ -602,25 +602,26 @@ _zsh_autosuggest_predefined_generate() {
# enumerate commands in $PATH and add them to ~/.zsh_autosuggest # enumerate commands in $PATH and add them to ~/.zsh_autosuggest
for p ("${(@s/:/)PATH}"); do for p ("${(@s/:/)PATH}"); do
cd "$p" [ ! -d "$p" ] && continue
local files=("${(@f)$(ls -la | awk -F ' ' '{print $9}')}") cd "$p"
for fn in ${files}; do local files=("${(@f)$(ls -la | awk -F ' ' '{print $9}')}")
if [ -x "$fn" ] && [[ "${fn:l}" != *.dll ]]; then for fn in ${files}; do
if [ -f "$fn" ] && [[ "${fn:l}" != *.nls ]]; then if [ -x "$fn" ] && [[ "${fn:l}" != *.dll ]]; then
# trim cygwin .exe/.cmd/.bat postfix if [ -f "$fn" ] && [[ "${fn:l}" != *.nls ]]; then
if [[ "$fn" == *.exe ]]; then # trim cygwin .exe/.cmd/.bat postfix
fn=${fn/%.exe/} if [[ "$fn" == *.exe ]]; then
elif [[ "$fn" == *.cmd ]]; then fn=${fn/%.exe/}
fn=${fn/%.cmd/} elif [[ "$fn" == *.cmd ]]; then
elif [[ "$fn" == *.bat ]]; then fn=${fn/%.cmd/}
fn=${fn/%.bat/} elif [[ "$fn" == *.bat ]]; then
fi fn=${fn/%.bat/}
if [[ ${#fn} -gt 1 ]]; then fi
suggests+=$fn if [[ ${#fn} -gt 1 ]]; then
fi suggests+=$fn
fi fi
fi fi
done fi
done
done done
cd "${pwd}" cd "${pwd}"
@ -644,7 +645,7 @@ _zsh_autosuggest_strategy_predefined() {
# search the predefine files if nothing found in history # search the predefine files if nothing found in history
if [[ -z "$result" ]]; then if [[ -z "$result" ]]; then
if (( ! ${+_ZSH_AUTOSUGGEST_PREDEFINE} )); then if (( ! ${+_ZSH_AUTOSUGGEST_PREDEFINE} )); then
_zsh_autosuggest_predefined_generate # _zsh_autosuggest_predefined_generate
typeset -g _ZSH_AUTOSUGGEST_PREDEFINE=() typeset -g _ZSH_AUTOSUGGEST_PREDEFINE=()
local pbase="$_zsh_autosuggest_data_home" local pbase="$_zsh_autosuggest_data_home"
local pname="$pbase/predefined" local pname="$pbase/predefined"
@ -665,7 +666,7 @@ _zsh_autosuggest_strategy_predefined() {
} }
# _zsh_autosuggest_predefined_generate _zsh_autosuggest_predefined_generate
# vim: set ts=4 sw=4 tw=0 noet : # vim: set ts=4 sw=4 tw=0 noet :