2023-05-02 10:27:57 +00:00
|
|
|
# The version of the format of .rake_tasks. If the output of _rake_generate
|
|
|
|
# changes, incrementing this number will force it to regenerate
|
|
|
|
_rake_tasks_version=2
|
|
|
|
|
2014-02-13 17:27:00 +00:00
|
|
|
_rake_does_task_list_need_generating () {
|
2023-05-02 10:27:57 +00:00
|
|
|
_rake_tasks_missing || _rake_tasks_version_changed || _rakefile_has_changes || { _is_rails_app && _tasks_changed }
|
|
|
|
}
|
|
|
|
|
|
|
|
_rake_tasks_missing () {
|
|
|
|
[[ ! -f .rake_tasks ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
_rake_tasks_version_changed () {
|
|
|
|
local -a file_version
|
|
|
|
file_version=`head -n 1 .rake_tasks | sed "s/^version\://"`
|
|
|
|
|
|
|
|
if ! [[ $file_version =~ '^[0-9]*$' ]]; then
|
|
|
|
return true
|
|
|
|
fi
|
|
|
|
|
|
|
|
[[ $file_version -ne $_rake_tasks_version ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
_rakefile_has_changes () {
|
|
|
|
[[ Rakefile -nt .rake_tasks ]]
|
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 () {
|
2023-05-02 10:27:57 +00:00
|
|
|
echo "version:$_rake_tasks_version" > .rake_tasks
|
|
|
|
|
|
|
|
rake --silent --tasks --all \
|
|
|
|
| sed "s/^rake //" | sed "s/\:/\\\:/g" \
|
|
|
|
| sed "s/\[[^]]*\]//g" \
|
|
|
|
| sed "s/ *# /\:/" \
|
|
|
|
| sed "s/\:$//" \
|
|
|
|
>> .rake_tasks
|
2014-02-13 17:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_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
|
2023-05-02 10:27:57 +00:00
|
|
|
local -a rake_options
|
|
|
|
rake_options=("${(@f)$(cat .rake_tasks)}")
|
|
|
|
shift rake_options
|
|
|
|
_describe 'rake tasks' rake_options
|
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
|
|
|
|
}
|