Zsh menu completion causes problems after zle reset-prompt

可紊 提交于 2019-11-29 06:21:59

I found this workaround, to basically prevent calling "reset-prompt" when in a menu selection :

TRAPALRM() {
    if [ "$WIDGET" != "complete-word" ]; then
        zle reset-prompt
    fi
}

Note that complete-word may be different for you; I found it with an echo $WIDGET in the TRAPALRM call.

My solution for this issue is to check both $WIDGET and $_lastcomp[insert] values to know if menu-select is active at the moment more precisely.

autoload -U is-at-least
TMOUT=1
if is-at-least 5.1; then
    # avoid menuselect to be cleared by reset-prompt
    redraw_tmout() {
        [ "$WIDGET" = "expand-or-complete" ] && [[ "$_lastcomp[insert]" =~ "^automenu$|^menu:" ]] || zle reset-prompt
    }
else
    # evaluating $WIDGET in TMOUT may crash :(
    redraw_tmout() { zle reset-prompt }
fi
TRAPALRM() { redraw_tmout }

The "expand-or-complete" might be "complete-word" or something, based on the key bind to your tab key. It can be checked by the bindkey "^I" command.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!