나는 expect
zsh에서 자동 완성을 테스트하는 데 사용하고 있습니다(실제로 Ruby gem을 사용하여 내부적으로 greenletters
Ruby를 사용하여 호출 ). 문서와 오래된 아카이브를 파헤친 후(이것이 아래 코드를 제공한 마지막 코멘트였습니다.PTY
expect
https://narkive.com/jbOlxniA:5.2481.94) '깨끗한' 시스템에서 완성을 쉽게 로드하는 다음과 같은 방법이 있습니다.
PROMPT='>' zsh -f
fpath+=($PWD/Completion)
autoload -Uz compinit
_compdir=$PWD/Completion compinit -D
이제 수동으로 파일을 생성하고 이런 방식으로 로드하면 작동합니다.완벽하게 괜찮아. 그러나 라이브러리를 사용하여 로드하려고 하면 greenletters
완료 항목이 로드되지 않습니다.
>options Completion/
------------------------------------------------------------
다음은 Ruby로 작성된 SSCCE입니다(간단한 expect
스크립트로 동일한 예제를 만드는 데 어려움을 겪고 있습니다). gem install greenletters
이 스크립트를 실행하려면 다음을 실행해야 합니다 .
require 'tempfile'
require 'greenletters'
require 'tmpdir'
@tempdir = Dir.mktmpdir
completions_folder = @tempdir + '/Completion'
FileUtils.mkdir_p(completions_folder)
@completion_script = Tempfile.create('_completion', completions_folder)
@completion_script.write(DATA)
puts @tempdir
@adv = Greenletters::Process.new("PROMPT='>' zsh -f", transcript: $stdout, timeout: 3)
@adv.start!
@adv.wait_for(:output, />/i)
@adv << "cd #{@tempdir}\r"
@adv.wait_for(:output, />/i)
@adv << "fpath+=($PWD/Completion)\r"
@adv.wait_for(:output, />/i)
@adv << "autoload -Uz compinit\r"
@adv.wait_for(:output, />/i)
@adv << "_compdir=$PWD/Completion compinit -D\r"
@adv.wait_for(:output, />/i)
@adv << "options \t"
@adv.wait_for(:output, />/i)
__END__
#compdef _options options
function _options_help {
_arguments \
"-h[Show help information]" \
"--help[Show help information]"
}
function _options_desc {
_arguments \
"--test=[desc]" \
"-h[Show help information]" \
"--help[Show help information]"
}
function _options {
local line
local -a commands
commands=(
'desc:use description flag for description'
'help:Describe available commands or one specific command'
)
_arguments \
"-h[Show help information]" \
"--help[Show help information]" \
"1: : _describe 'command' commands" \
"*::arg:->args"
case $state in
args)
case $line[1] in
desc)
_options_desc
;;
help)
_options_help
;;
esac
;;
esac
}
_options "$@"
zsh는 일반 로딩과 PTY에서 다르게 작동합니까? 이것이 일반적인 PTY에 대해 내가 이해하지 못하는 것입니까? 다들 이렇게 일하나요?