완료를 취소하지만 zsh에서는 완료만 취소합니다.

완료를 취소하지만 zsh에서는 완료만 취소합니다.

기능을 완료하는 데 오랜 시간이 걸리는 경우,내가 방해할 수 있어Ctrl+ C(터미널 인터럽트 키, SIGINT 전송) 또는 Ctrl+ G(바인딩 )를 누릅니다 send-break. 그러다가 끝나지 않은 말만 남았습니다.

그러나 완료 기능이 완료되는 동안 Ctrl+ C또는 Ctrl+를 누르면 G키 입력으로 인해 명령줄이 취소되고 완료를 취소하는 대신 새 프롬프트가 표시될 수 있습니다.

특정 키가 진행 중인 완료를 취소하지만 완료가 활성화되지 않으면 아무 작업도 수행하지 않도록 zsh를 어떻게 설정할 수 있습니까?

답변1

완료가 활성화될 때만 중단되는 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
}

답변2

이것이 수용 가능한 해결책인지는 모르겠지만 SIGSTOP( Ctrl+ )을 보내는 것이 원하는 효과를 갖는 것 같습니다. 입력하기 전에 SIGSTART( + )를 보내는 경우 S자동 완성을 다시 시작할 수 있다는 추가 이점도 있습니다. 하지만 저는 직무 통제 전문가가 아니기 때문에 직무 중단과 관련하여 추가적인 혼란을 야기할 수 있습니다.CtrlQ

관련 정보