Zsh menu completion causes problems after zle reset-prompt

后端 未结 2 1140
太阳男子
太阳男子 2020-12-16 18:41

I have following code in my .zshrc:

TMOUT=1
TRAPALRM() { zle reset-prompt }

After triggering menu completion all items from menu, except hi

2条回答
  •  抹茶落季
    2020-12-16 19:27

    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.

提交回复
热议问题