3

I have oh-my-zsh installed with the rails plugin, when I use zsh completion with rake, it completes with the tasks list from rake -T.

When I run a specific test, one of the parameters is the path to the test file:

rake test test/models/dummy_model.rb

I often try to autocomplete this path and it obviously do not work.

rake test test/models/...

I would like to be able to complete from file paths in addition to tasks. How could I do this ?

3

If I get you right, this only occurs, when you use the form rake test .... Then you can use this patch against $fpath/_rake

diff --git a/Completion/Unix/Command/_rake b/Completion/Unix/Command/_rake
index 7fed949..96ee930 100644
--- a/Completion/Unix/Command/_rake
+++ b/Completion/Unix/Command/_rake
@@ -37,12 +37,16 @@ case "$state" in
   ;;
   target)
     local -a targets
-    targets=( ${${(f)"$(_call_program targets $words[1] -sT $opt_args[(I)(-N|--nosearch)] ${(kv)opt_args[(I)(-f|--rakefile)]} 2>/dev/null)"}/(#b)rake ([^ ]##) ##\# (*)/${${match[1]}//:/\\:}:${match[2]:l}} )
-    if (( ! ${targets[(I)rake aborted!]} )) then
-      _describe -t targets 'rake target' targets && ret=0
-    else
-      _message -e targets 'rake target'
-    fi
+    if [[ $words[$((CURRENT-1))] == "test" ]]; then
+       _files && ret=0
+       else
+           targets=( ${${(f)"$(_call_program targets $words[1] -sT $opt_args[(I)(-N|--nosearch)] ${(kv)opt_args[(I)(-f|--rakefile)]} 2>/dev/null)"}/(#b)rake ([^ ]##) ##\# (*)/${${match[1]}//:/\\:}:${match[2]:l}} )
+           if (( ! ${targets[(I)rake aborted!]} )) then
+             _describe -t targets 'rake target' targets && ret=0
+           else
+             _message -e targets 'rake target'
+           fi
+       fi
   ;;
 esac

That patch in principle adds the condition if [[ $words[$((CURRENT-1))] == "test" ]]; which checks if the previous argument equals "test". And if so, files and directories are returned via the _files function instead of rake targets.

  • Awesome ! Thanks you very much, it worked perfectly. For the record, on OS X Yosemite, the file path is /usr/share/zsh/5.0.5/functions/_rake (/usr/share/zsh/5.0.2/functions/_rake on OS X Mavericks) – ybart Aug 1 '14 at 7:40
  • This should be in the official completion file. Why you don't submit a patch?? – Pablo Olmos de Aguilera C. Jan 2 '15 at 17:34
  • Patches are not currently being accepted via the SourceForge ticketing tools. The shell is being maintained by various (entirely self-appointed) subscribers to the mailing list, zsh-workers@zsh.org so mail about any issues (bug reports, suggestions, complaints...) related to the development of the shell should be sent there. If you want someone to mail you directly, say so. Most patches to zsh appear there first. – Pablo Olmos de Aguilera C. Jan 2 '15 at 17:47
  • @pablox Please feel free to submit this patch to zsh-workers. I haven't done it myself as I don't know rake and hence cannot judge if it only addresses a special case or make sense generally. – mpy Jan 2 '15 at 21:00
  • I'll continue using a couple of days more, but until now it seems okay :). How did you learn to make zsh completions? – Pablo Olmos de Aguilera C. Jan 4 '15 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.