2014-02-14 01:27:00 +08:00
|
|
|
_rake_does_task_list_need_generating () {
|
2016-08-22 01:51:08 +08:00
|
|
|
[[ ! -f .rake_tasks ]] || [[ Rakefile -nt .rake_tasks ]] || { _is_rails_app && _tasks_changed }
|
2016-08-14 02:47:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_is_rails_app () {
|
2016-08-22 01:51:08 +08:00
|
|
|
[[ -e "bin/rails" ]] || [[ -e "script/rails" ]]
|
2016-08-14 02:47:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_tasks_changed () {
|
2016-08-22 01:50:44 +08:00
|
|
|
local -a paths
|
|
|
|
paths=(lib/tasks lib/tasks/**/*(N))
|
|
|
|
|
|
|
|
for path in $paths; do
|
|
|
|
if [[ "$path" -nt .rake_tasks ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2016-08-14 02:47:43 +08:00
|
|
|
done
|
2016-08-22 01:50:44 +08:00
|
|
|
|
|
|
|
return 1
|
2014-02-14 01:27:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_rake_generate () {
|
|
|
|
rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
|
|
|
|
}
|
|
|
|
|
|
|
|
_rake () {
|
2016-08-22 01:51:08 +08:00
|
|
|
if [[ -f Rakefile ]]; then
|
2014-02-14 01:27:00 +08:00
|
|
|
if _rake_does_task_list_need_generating; then
|
2016-08-22 01:51:08 +08:00
|
|
|
echo "\nGenerating .rake_tasks..." >&2
|
2014-02-14 01:27:00 +08:00
|
|
|
_rake_generate
|
|
|
|
fi
|
2016-08-22 01:51:08 +08:00
|
|
|
compadd $(cat .rake_tasks)
|
2014-02-14 01:27:00 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
compdef _rake rake
|
2016-08-22 01:51:08 +08:00
|
|
|
|
|
|
|
rake_refresh () {
|
|
|
|
[[ -f .rake_tasks ]] && rm -f .rake_tasks
|
|
|
|
|
|
|
|
echo "Generating .rake_tasks..." >&2
|
|
|
|
_rake_generate
|
|
|
|
cat .rake_tasks
|
|
|
|
}
|