rake-fast.plugin.zsh 842 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
12
13
14
15
16
  local -a paths
  paths=(lib/tasks lib/tasks/**/*(N))

  for path in $paths; do
    if [[ "$path" -nt .rake_tasks ]]; then
      return 0
    fi
17
  done
18
19

  return 1
20
21
22
23
24
25
26
}

_rake_generate () {
  rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
}

_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
}