0

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?

10
  • What's the problem? I do see a prompt to complete desc or help. Then the script times out because it expects a new prompt, not completion offerings. Commented Apr 2, 2020 at 18:33
  • You see a prompt with the ruby script??? It tries to complete the file names for me, not the options for the completion. Commented Apr 2, 2020 at 18:37
  • I updated the script because I wasn't cd'ing to the temporary directory (whoops), so I'm really not sure how it worked for you at this point. Commented Apr 2, 2020 at 18:48
  • I ran the original script in the same directory where I'd created a Completion directory 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. Commented Apr 3, 2020 at 9:14
  • 1
    The bug is in your ruby script. It doesn't create the file as expected. Increase the timeout and look at the content of the temp directory: _completionXXXX is empty. I guess you need to flush after writing. Commented Apr 3, 2020 at 16:26

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.