1 Star 2 Fork 0

2h1c/incr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
incr-0.2.zsh 2.57 KB
一键复制 编辑 原始数据 按行查看 历史
2h1c 提交于 2022-07-05 14:47 . init
# Incremental completion for zsh
# by y.fujii <y-fujii at mimosa-pudica.net>, public domain
autoload -U compinit
zle -N self-insert self-insert-incr
zle -N vi-cmd-mode-incr
zle -N vi-backward-delete-char-incr
zle -N backward-delete-char-incr
zle -N expand-or-complete-prefix-incr
compinit
bindkey -M viins '^[' vi-cmd-mode-incr
bindkey -M viins '^h' vi-backward-delete-char-incr
bindkey -M viins '^?' vi-backward-delete-char-incr
bindkey -M viins '^i' expand-or-complete-prefix-incr
bindkey -M emacs '^h' backward-delete-char-incr
bindkey -M emacs '^?' backward-delete-char-incr
bindkey -M emacs '^i' expand-or-complete-prefix-incr
unsetopt automenu
compdef -d scp
compdef -d tar
compdef -d make
compdef -d java
compdef -d svn
compdef -d cvs
# TODO:
# cp dir/
now_predict=0
function limit-completion
{
if ((compstate[nmatches] <= 1)); then
zle -M ""
elif ((compstate[list_lines] > 6)); then
compstate[list]=""
zle -M "too many matches."
fi
}
function correct-prediction
{
if ((now_predict == 1)); then
if [[ "$BUFFER" != "$buffer_prd" ]] || ((CURSOR != cursor_org)); then
now_predict=0
fi
fi
}
function remove-prediction
{
if ((now_predict == 1)); then
BUFFER="$buffer_org"
now_predict=0
fi
}
function show-prediction
{
# assert(now_predict == 0)
if
((PENDING == 0)) &&
((CURSOR > 1)) &&
[[ "$PREBUFFER" == "" ]] &&
[[ "$BUFFER[CURSOR]" != " " ]]
then
cursor_org="$CURSOR"
buffer_org="$BUFFER"
comppostfuncs=(limit-completion)
zle complete-word
cursor_prd="$CURSOR"
buffer_prd="$BUFFER"
if [[ "$buffer_org[1,cursor_org]" == "$buffer_prd[1,cursor_org]" ]]; then
CURSOR="$cursor_org"
if [[ "$buffer_org" != "$buffer_prd" ]] || ((cursor_org != cursor_prd)); then
now_predict=1
fi
else
BUFFER="$buffer_org"
CURSOR="$cursor_org"
fi
echo -n "\e[32m"
else
zle -M ""
fi
}
function preexec
{
echo -n "\e[39m"
}
function vi-cmd-mode-incr
{
correct-prediction
remove-prediction
zle vi-cmd-mode
}
function self-insert-incr
{
correct-prediction
remove-prediction
if zle .self-insert; then
show-prediction
fi
}
function vi-backward-delete-char-incr
{
correct-prediction
remove-prediction
if zle vi-backward-delete-char; then
show-prediction
fi
}
function backward-delete-char-incr
{
correct-prediction
remove-prediction
if zle backward-delete-char; then
show-prediction
fi
}
function expand-or-complete-prefix-incr
{
correct-prediction
if ((now_predict == 1)); then
CURSOR="$cursor_prd"
now_predict=0
comppostfuncs=(limit-completion)
zle list-choices
else
remove-prediction
zle expand-or-complete-prefix
fi
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/c1h2/incr.git
git@gitee.com:c1h2/incr.git
c1h2
incr
incr
master

搜索帮助