Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zsh menu completion causes problems after zle reset-prompt

I have following code in my .zshrc:

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

After triggering menu completion all items from menu, except highlighted one disappear after TRAPALRM triggers and when i keep navigating in menu zsh segvaults after a short time

Is there any fix or workaround for this?

EDIT: zsh version is 5.0.2 on Linux Mint 17

EDIT: i observe same thing on zsh version 5.0.7 on Gentoo

like image 668
Ryba Avatar asked Oct 23 '14 10:10

Ryba


2 Answers

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.

like image 115
NeoCat Avatar answered Sep 19 '22 13:09

NeoCat


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.

like image 34
Drasill Avatar answered Sep 20 '22 13:09

Drasill