I'm using expect to test autocompletions in zsh (actually using the Ruby greenletters gem, with uses Ruby's PTY under the covers, to call expect). After digging through the documentation and old archives (this was the final comment that gave me the below code: https://narkive.com/jbOlxniA:5.2481.94) I have this way of easily loading the completion on a 'clean' system:
PROMPT='>' zsh -f
fpath+=($PWD/Completion)
autoload -Uz compinit
_compdir=$PWD/Completion compinit -D
Now, creating a file manually and loading it this way works perfectly fine. But, as soon as I try to load it using the greenletters library it doesn't load any completions:
>options Completion/
------------------------------------------------------------
Here is a SSCCE written in ruby (I'm having trouble creating the same example in a simple expect script). You'll need to run gem install greenletters to be able to run this script:
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 "$@"
Does zsh act differently in a PTY than regular loading? Is this something I just don't understand about PTYs in general? Do they all work like this?
descorhelp. Then the script times out because it expects a new prompt, not completion offerings.Completiondirectory to try manually. Maybe a typo somewhere in the script causing something not to be loaded? I don't know ruby so I didn't review the script._completionXXXXis empty. I guess you need to flush after writing.