minitest / minitest-sprint

39 stars 1 forks source link

zsh autocomplete #1

Open squarism opened 9 years ago

squarism commented 9 years ago

I saw the note about making a PR to confirm that it works for zsh users. I couldn't get it to work so I'm opening an issue to help document and assist. :)

I think the problem is that zsh doesn't have COMP_LINE. So an exception is thrown on a nil value. Manually setting COMP_LINE fixes it but the actual value obviously needs to be dynamic for it to be useful.

  # ... <TAB><TAB>
  minitest ~/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/shellwords.rb:73:in `shellsplit': undefined method 
   `scan' for nil:NilClass (NoMethodError)
  from ~/.rvm/gems/ruby-2.1.5/gems/minitest-sprint-1.1.0/lib/minitest/complete.rb:8:in `<main>'

I then tried to get the bash compatibility options to work with zsh but my initial attempts have failed. This is in the context of oh-my-zsh. So maybe a vanilla zsh user would have more luck with their .zshrc config. I think a good solution would be to write a oh-my-zsh plugin and change minitest/complete.rb to handle whatever environment differences are between the two shells. But I haven't figured this out yet. I took at stab at a zsh plugin but I need to work on it some more.

I switched to bash temporarily to get the happy path working and developed against that state. Of course it works. :) So, this is definitely zsh related. I'm hoping I can contribute something more substantial.

zenspider commented 9 years ago

Awesome! Thanks! I'll get some ppl from IRC to put eyeballs on this.

baweaver commented 9 years ago

Code area: https://github.com/seattlerb/minitest-sprint/blob/master/lib/minitest/complete.rb#L8

baweaver commented 9 years ago

I switched to Bash but didn't have the env variable in either one. What is it normally?

baweaver commented 9 years ago

This looks handy: http://blogs.perl.org/users/perlancar/2014/11/comparing-programmable-tab-completion-in-bash-zsh-tcsh-and-fish.html

zenspider commented 9 years ago

zsh code of interest:

% _mycompleter() { read -l; local cl="$REPLY"; read -ln; local cp="$REPLY"; reply=(`COMP_SHELL=zsh COMP_LINE="$cl" COMP_POINT="$cp" mycompleter`) }
% compctl -K _mycompleter someprog

vs bash:

complete -C mycompleter someprog

where mycompleter is an external command in bash, but can't be in zsh.

baweaver commented 9 years ago

Yeah, that sites pre tags have hidden overflows, so fair warning.

squarism commented 9 years ago

COMPLINE gets evaluated when you hit <TAB><TAB> in bash. You can see it if you just putsit in the minitest/complete.rb For example, it's probably `minitest -n test` if you follow the (bash) README. I think a port (like the _mycompleter function you mention up there) would work if you could get bash compatibility to work. I tried a few different ways but couldn't get the COMP_LINE to show up anywhere.

So then I switched to trying to get a zsh plugin (specifically oh-my-zsh) to work. But I've never written one so it's trial-by-fire. :fire: :smile:

zenspider commented 9 years ago

Unassigning so people might be encouraged to help on this more.