매개변수에 대한 메시지는 어디에 표시됩니까?

매개변수에 대한 메시지는 어디에 표시됩니까?

저는 zsh 완성 스크립트를 작성하는 방법을 배우고 있는데 문서를 읽는 동안 _arguments다음 부분을 발견했습니다.

n: 메시지: 동작
n::메시지:작업
    n번째 일반 매개변수를 설명합니다. 이것정보
    생성된 일치 항목 위에 인쇄됩니다 .행동표현하다[...]

그게 어디야?정보인쇄? 다음과 같은 최소한의 기능을 시도하고 있지만 이해할 수 없습니다. 셸에서 특정 기능을 활성화해야 합니까?

function _test {
  _arguments '-a' '-b[description]:my message:(x y)'
}
$ compdef _test program

그 결과는 다음과 같습니다.

$ program -b <tab>
x y

답변1

어디를 봐야 할지 알면 설명서에 나와 있지만 설명 방식을 보면 실제로 설명서의 내용을 이해하려면 답을 알아야 합니다.

_arguments이를 "메시지"라고 부르고 매뉴얼에서는 "설명"이라고 부릅니다. 그래서 당신은 확신합니다. 또는 소스 코드를 읽고 _arguments이 메시지가 다음으로 전달되고 있음을 알게 됩니다._describe. 이 기능에 대한 문서에는 다음과 같은 내용이 나와 있습니다.

레이블에 스타일이 지정되면 descr일치 항목 위에 표시되는 문자열로 처리됩니다.formatdescriptions

스타일은 사용자가 구성하는 것입니다.zstyle. 이것"전체 시스템 구성" 섹션완성 스타일 기록 형식:

필드는 항상 순서대로 되어 있습니다 :completion:function:completer:command:argument:tag.

그래서 전화해야합니다. 또는 특정 상황에서만 이 작업을 수행하려면 다른 것으로 바꾸십시오.zstyle ':completion:*:*:*:*:descriptions' format=SOMETHING*

이것문서 descriptions태그현 단계에서는 별 도움이 안 되지만,문서 format스타일예:

설명 태그에 대해 이 값이 설정된 경우 해당 값은 위 일치 항목을 완성 목록에 표시하는 문자열로 사용됩니다. 이 문자열의 시퀀스는 %d이러한 일치 항목에 대한 간단한 설명으로 대체됩니다. 문자열에는 다음이 이해하는 일련의 출력 속성이 포함될 수도 있습니다.compadd -X

보다compadd문서화는 주로 사용할 수 있는 급속한 확장을 의미합니다.시각 효과.

그러니 달려라

zstyle ':completion:*:*:*:*:descriptions' format '%F{green}%d%f'

완료 위에 녹색 메시지가 표시됩니다. 또는

zstyle ':completion:*:*:program:*:descriptions' format '%F{green}%d%f'

매개 변수가 완료된 경우에만 적용하려는 경우 program.

답변2

완성된 zstyle을 설정해야 합니다 format:

zstyle ':completion:*' format 'Completing %d'

그 다음에:

$ 프로그램-bTab
내 메시지를 완성하세요
XY

info zsh format자세히보다.

compinstall이 메뉴 선택을 따라 설정하는 경우:

3.  Styles for changing the way completions are displayed and inserted.
[...]
1.  Change appearance of completion lists:  allows descriptions of
    completions to appear and sorting of different types of completions.
[...]
1.  Print a message above completion lists describing what is being
    completed.
[...]
You can set a string which is displayed on a line above the list of matches
for completions.  A `%d' in this string will be replaced by a brief
description of the type of completion.  For example, if you set the
string to `Completing %d', and type ^D to show a list of files, the line
`Completing files' will appear above that list.  Enter an empty line to
turn this feature off.  If you enter something which doesn't include `%d',
then `%d' will be appended.  Quotation will be added automatically.

description>

관련 정보