完了をキャンセルしますが、zshは完了のみをキャンセルします。

完了をキャンセルしますが、zshは完了のみをキャンセルします。

機能の完了に長い時間がかかる場合、私が邪魔することができますCtrl+ C(ターミナル割り込みキー、SIGINT転送)またはCtrl+ G(バインディング)を押しますsend-break。それから終わらなかった言葉だけが残りました。

ただし、完了機能の完了中にCtrl+CまたはCtrl+を押すと、キーG入力によってコマンドラインがキャンセルされ、完了をキャンセルする代わりに新しいプロンプトが表示されることがあります。

特定のキーが進行中の完了をキャンセルしても完了が有効になっていない場合は、何もしないようにzshをどのように設定できますか?

ベストアンサー1

完了が有効になったときにのみ中断されるSIGINTハンドラを設定するソリューションは次のとおりです CtrlC

# A completer widget that sets a flag for the duration of
# the completion so the SIGINT handler knows whether completion
# is active. It would be better if we could check some internal
# zsh parameter to determine if completion is running, but as 
# far as I'm aware that isn't possible.
function interruptible-expand-or-complete {
    COMPLETION_ACTIVE=1

    # Bonus feature: automatically interrupt completion
    # after a three second timeout.
    # ( sleep 3; kill -INT $$ ) &!

    zle expand-or-complete

    COMPLETION_ACTIVE=0
}

# Bind our completer widget to tab.
zle -N interruptible-expand-or-complete
bindkey '^I' interruptible-expand-or-complete

# Interrupt only if completion is active.
function TRAPINT {
    if [[ $COMPLETION_ACTIVE == 1 ]]; then
        COMPLETION_ACTIVE=0
        zle -M "Completion canceled."            

        # Returning non-zero tells zsh to handle SIGINT,
        # which will interrupt the completion function. 
        return 1
    else
        # Returning zero tells zsh that we handled SIGINT;
        # don't interrupt whatever is currently running.
        return 0
    fi
}

おすすめ記事