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