我正在使用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 的一般不理解嗎?他們都是這樣運作的嗎?