파일을 찾을 수 없다고 말하는 대신 실행 파일을 검색할 수 있는 위치를 설명하도록 zsh를 구성하려면 어떻게 해야 합니까?

파일을 찾을 수 없다고 말하는 대신 실행 파일을 검색할 수 있는 위치를 설명하도록 zsh를 구성하려면 어떻게 해야 합니까?

기본 구성세게 때리다존재하다우분투, 설치되지 않은 소프트웨어의 이름을 입력하면세게 때리다실행 파일이 있는 경우 설치하는 방법, 없는 경우 매우 유사한 이름의 실행 파일을 설치하는 방법을 설명합니다. 예를 들어이맥스(내 컴퓨터에는 설치되어 있지 않음):

$ emacx
No command 'emacx' found, did you mean:
 Command 'emacs' from package 'emacs23-lucid' (universe)
 Command 'emacs' from package 'e3' (universe)
 Command 'emacs' from package 'emacs23-nox' (main)
 Command 'emacs' from package 'emacs24' (main)
 Command 'emacs' from package 'emacs24-nox' (main)
 Command 'emacs' from package 'emacs23' (main)
 Command 'emacs' from package 'jove' (universe)
 Command 'emacs' from package 'emacs24-lucid' (universe)
emacx: command not found
$ emacs
The program 'emacs' can be found in the following packages:
 * emacs23
 * emacs23-nox
 * emacs24
 * emacs24-nox
 * e3
 * emacs23-lucid
 * emacs24-lucid
 * jove
Try: sudo apt-get install <selected package>

현재 zsh 구성을 기반으로 다음을 얻습니다.

$ emacx
zsh: command not found: emacx
$ emacs
zsh: command not found: emacs

설치된 소프트웨어 이름에 오류가 있는 경우에도 동작이 다릅니다. 시작하고 싶다고 말해편집자바꾸다편집자. 그리고세게 때리다,나는 얻다:

$ kedit
No command 'kedit' found, did you mean:
 Command 'xedit' from package 'x11-apps' (main)
 Command 'edit' from package 'mime-support' (main)
 Command 'nedit' from package 'nedit' (universe)
 Command 'gedit' from package 'gedit' (main)
 Command 'jedit' from package 'jedit' (universe)
 Command 'medit' from package 'medit' (universe)
 Command 'ledit' from package 'ledit' (main)
kedit: command not found

zsh를 사용하면 다음을 얻습니다.

$ kedit
zsh: correct 'kedit' to 'edit' [nyae]?

그래서 내 질문은 다음과 같습니다.

  • 비슷한 행동이 가능할까요?그리고세게 때리다아직 설치되지 않은 실행 파일을 실행하려고 할 때? 그렇다면 어떻게?
  • 오타가 발생했을 때, 틀렸을지도 모르는 수정을 하는 대신 모든 가능성을 보여주는 것이 가능하지 않을까?

답변1

command-not-foundDebian(그리고 아마도 Ubuntu)의 기본 zsh 구성에는 기본 패키지에 대한 지원이 포함되어 있지 않습니다 .

동일한 기능을 사용하려면 다음을 통해 /etc/zsh_command_not_found기본값 을 얻을 수 있습니다 .~/.zshrc

[ -f /etc/zsh_command_not_found ] && . /etc/zsh_command_not_found

이 로드되어 command-not-found활성화되어야 합니다 zsh.

답변2

제가 지적하고 싶은 것은

[[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found

거의 정답입니다. 그러나 작은 문제가 있습니다.

일부 명령의 경우 결과가 전혀 반환되지 않습니다. 예를 들어 Bash에서 다음 명령을 시도해 보세요.

$ muxy
muxy: command not found
$ mury
mury: command not found

그러나 zsh를 사용하면 아무것도 얻지 못합니다. 오류 메시지가 없습니다.

$ muxy
$ murez

걱정하지 마세요. 해결책은 /etc/zsh_command_not_found파일에 있습니다.

if [[ -x /usr/lib/command-not-found ]] ; then
    if (( ! ${+functions[command_not_found_handler]} )) ; then
        function command_not_found_handler {
            [[ -x /usr/lib/command-not-found ]] || return 1
            /usr/lib/command-not-found --no-failure-msg -- ${1+"$1"} && :
        }
    fi
fi

여기서 문제는 --no-failure-msg...제거하면 문제가 해결된다는 것입니다.

내가 한 일은 [[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found.zshrc 를 사용하는 대신 .zshrc 파일에 다음 줄을 넣은 것입니다.

if [[ -x /usr/lib/command-not-found ]] ; then
    if (( ! ${+functions[command_not_found_handler]} )) ; then
        function command_not_found_handler {
            [[ -x /usr/lib/command-not-found ]] || return 1
            /usr/lib/command-not-found -- ${1+"$1"} && :
        }
    fi
fi

관련 정보