rake-fast.plugin.zsh 862 Bytes
Newer Older
1
_rake_does_task_list_need_generating () {
2
  [[ ! -f .rake_tasks ]] || [[ Rakefile -nt .rake_tasks ]] || { _is_rails_app && _tasks_changed }
3
4
5
}

_is_rails_app () {
6
  [[ -e "bin/rails" ]] || [[ -e "script/rails" ]]
7
8
9
}

_tasks_changed () {
10
11
  local -a files
  files=(lib/tasks lib/tasks/**/*(N))
12

13
14
  for file in $files; do
    if [[ "$file" -nt .rake_tasks ]]; then
15
16
      return 0
    fi
17
  done
18
19

  return 1
20
21
22
}

_rake_generate () {
23
  rake --silent --tasks | cut -d " " -f 2 | sed 's/\[.*\]//g' > .rake_tasks
24
25
26
}

_rake () {
27
  if [[ -f Rakefile ]]; then
28
    if _rake_does_task_list_need_generating; then
29
      echo "\nGenerating .rake_tasks..." >&2
30
31
      _rake_generate
    fi
32
    compadd $(cat .rake_tasks)
33
34
35
  fi
}
compdef _rake rake
36
37
38
39
40
41
42
43

rake_refresh () {
  [[ -f .rake_tasks ]] && rm -f .rake_tasks

  echo "Generating .rake_tasks..." >&2
  _rake_generate
  cat .rake_tasks
}