1a029f293541d37e545f4706791ca41ce129600b

Author
Kevin Bongart <contact@kevinbongart.net>
Committer
Kevin Bongart <contact@kevinbongart.net>
Date

Message

Add rake-fast plugin for fast rake autocompletion

Diff

 1diff --git a/plugins/rake-fast/rake-fast.plugin.zsh b/plugins/rake-fast/rake-fast.plugin.zsh
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..0c268355ef04d2758c39cbf4071b406522c719b0
 4--- /dev/null
 5+++ b/plugins/rake-fast/rake-fast.plugin.zsh
 6@@ -0,0 +1,56 @@
 7+# rake-fast
 8+# Fast rake autocompletion plugin for oh-my-zsh
 9+
10+# This script caches the output for later usage and significantly speeds it up.
11+# It generates a .rake_tasks file in parallel to the Rakefile.
12+
13+# You'll want to add `.rake_tasks` to your global .git_ignore file:
14+# https://help.github.com/articles/ignoring-files#global-gitignore
15+
16+# You can force .rake_tasks to refresh with:
17+# $ rake_refresh
18+
19+# This is entirely based on Ullrich Schäfer's work
20+# (https://github.com/robb/.dotfiles/pull/10/),
21+# which is inspired by this Ruby on Rails trick from 2006:
22+# http://weblog.rubyonrails.org/2006/3/9/fast-rake-task-completion-for-zsh/
23+
24+# Author: Kevin Bongart
25+# contact@kevinbongart.net
26+# http://kevinbongart.net
27+# https://github.com/KevinBongart
28+
29+_rake_refresh () {
30+  if [ -f .rake_tasks ]; then
31+    rm .rake_tasks
32+  fi
33+  echo "Generating .rake_tasks..." > /dev/stderr
34+  _rake_generate
35+  cat .rake_tasks
36+}
37+
38+_rake_does_task_list_need_generating () {
39+  if [ ! -f .rake_tasks ]; then return 0;
40+  else
41+    accurate=$(stat -f%m .rake_tasks)
42+    changed=$(stat -f%m Rakefile)
43+    return $(expr $accurate '>=' $changed)
44+  fi
45+}
46+
47+_rake_generate () {
48+  rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
49+}
50+
51+_rake () {
52+  if [ -f Rakefile ]; then
53+    if _rake_does_task_list_need_generating; then
54+      echo "\nGenerating .rake_tasks..." > /dev/stderr
55+      _rake_generate
56+    fi
57+    compadd `cat .rake_tasks`
58+  fi
59+}
60+
61+compdef _rake rake
62+alias rake_refresh='_rake_refresh'