Answers:
这是一个设置SIGINT处理程序的解决方案,该处理程序在激活完成时仅使Ctrl+ C中断。
# 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
}
我不知道这是否是可以接受的解决方案,但是发送SIGSTOP(Ctrl+ S)似乎达到了预期的效果,另外的好处是,如果在键入之前发送SIGSTART(Ctrl+ Q),则可以再次启动自动完成功能还要别的吗。我不是工作控制方面的专家,因此这可能会导致与已停止工作有关的其他混乱情况。