2e06412ee070a102b81d80bd39e637d2f87bf1b2
- Author
- Robby Russell <robby@planetargon.com>
- Committer
- Robby Russell <robby@planetargon.com>
- Date
Message
Merge pull request #2531 from KevinBongart/rake-fast
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..320855233f38a5d5e342f5cc04b85a73c3785c50
4--- /dev/null
5+++ b/plugins/rake-fast/rake-fast.plugin.zsh
6@@ -0,0 +1,51 @@
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+_rake_refresh () {
25+ if [ -f .rake_tasks ]; then
26+ rm .rake_tasks
27+ fi
28+ echo "Generating .rake_tasks..." > /dev/stderr
29+ _rake_generate
30+ cat .rake_tasks
31+}
32+
33+_rake_does_task_list_need_generating () {
34+ if [ ! -f .rake_tasks ]; then return 0;
35+ else
36+ accurate=$(stat -f%m .rake_tasks)
37+ changed=$(stat -f%m Rakefile)
38+ return $(expr $accurate '>=' $changed)
39+ fi
40+}
41+
42+_rake_generate () {
43+ rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
44+}
45+
46+_rake () {
47+ if [ -f Rakefile ]; then
48+ if _rake_does_task_list_need_generating; then
49+ echo "\nGenerating .rake_tasks..." > /dev/stderr
50+ _rake_generate
51+ fi
52+ compadd `cat .rake_tasks`
53+ fi
54+}
55+
56+compdef _rake rake
57+alias rake_refresh='_rake_refresh'