1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-11 00:10:08 +00:00

feat(rake-fast): show task descriptions in autocomplete (#11653)

This commit is contained in:
Oleg Grigoriev 2023-05-02 13:27:57 +03:00 committed by GitHub
parent 693e3dcc44
commit dab09cc0ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,28 @@
# 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
_rake_does_task_list_need_generating () { _rake_does_task_list_need_generating () {
[[ ! -f .rake_tasks ]] || [[ Rakefile -nt .rake_tasks ]] || { _is_rails_app && _tasks_changed } _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 ]]
} }
_is_rails_app () { _is_rails_app () {
@ -20,7 +43,14 @@ _tasks_changed () {
} }
_rake_generate () { _rake_generate () {
rake --silent --tasks | cut -d " " -f 2 | sed 's/\[.*\]//g' > .rake_tasks 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
} }
_rake () { _rake () {
@ -29,7 +59,10 @@ _rake () {
echo "\nGenerating .rake_tasks..." >&2 echo "\nGenerating .rake_tasks..." >&2
_rake_generate _rake_generate
fi fi
compadd $(cat .rake_tasks) local -a rake_options
rake_options=("${(@f)$(cat .rake_tasks)}")
shift rake_options
_describe 'rake tasks' rake_options
fi fi
} }
compdef _rake rake compdef _rake rake