a7e79824f85a89cbcacbceab0277c9833dee4817

Author
Mikhail S. Pobolovets <styx.mp@gmail.com>
Committer
ncanceill <nicolas.canceill@ens-cachan.org>
Date

Message

Add mix-fast plugin (similar to rake-fast)

Signed-off-by: Mikhail S. Pobolovets <styx.mp@gmail.com>

Diff

 1diff --git a/plugins/mix-fast/README.md b/plugins/mix-fast/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..9a5eccc3f675937adb0291a5123903e16b89a678
 4--- /dev/null
 5+++ b/plugins/mix-fast/README.md
 6@@ -0,0 +1,28 @@
 7+# mix-fast
 8+
 9+Fast mix autocompletion plugin.
10+
11+This script caches the output for later usage and significantly speeds it up.
12+It generates a .mix_tasks cache file for current project. Currently if you want
13+to update cache you should remove .mix_tasks file
14+
15+Inspired by and based on rake-fast zsh plugin.
16+
17+This is entirely based on [this pull request by Ullrich Schäfer](https://github.com/robb/.dotfiles/pull/10/), which is inspired by [this Ruby on Rails trick from 2006](http://weblog.rubyonrails.org/2006/3/9/fast-mix-task-completion-for-zsh/).
18+
19+
20+## Installation
21+
22+Just add the plugin to your `.zshrc`:
23+
24+```bash
25+plugins=(foo bar mix-fast)
26+```
27+
28+You might consider adding `.mix_tasks` to your [global .gitignore](https://help.github.com/articles/ignoring-files#global-gitignore)
29+
30+## Usage
31+
32+`mix`, then press tab
33+
34+Currently maintained by [styx](https://github.com/styx/)
35diff --git a/plugins/mix-fast/mix-fast.plugin.zsh b/plugins/mix-fast/mix-fast.plugin.zsh
36new file mode 100644
37index 0000000000000000000000000000000000000000..3719c352554cf63546b1212a310c311dd9efb2e4
38--- /dev/null
39+++ b/plugins/mix-fast/mix-fast.plugin.zsh
40@@ -0,0 +1,29 @@
41+_mix_refresh () {
42+  if [ -f .mix_tasks ]; then
43+    rm .mix_tasks
44+  fi
45+  echo "Generating .mix_tasks..." > /dev/stderr
46+  _mix_generate
47+  cat .mix_tasks
48+}
49+
50+_mix_does_task_list_need_generating () {
51+  [ ! -f .mix_tasks ];
52+}
53+
54+_mix_generate () {
55+  mix --help | grep -v 'iex -S' | tail -n +2 | cut -d " " -f 2 > .mix_tasks
56+}
57+
58+_mix () {
59+  if [ -f mix.exs ]; then
60+    if _mix_does_task_list_need_generating; then
61+      echo "\nGenerating .mix_tasks..." > /dev/stderr
62+      _mix_generate
63+    fi
64+    compadd `cat .mix_tasks`
65+  fi
66+}
67+
68+compdef _mix mix
69+alias mix_refresh='_mix_refresh'