mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-18 10:22:00 +00:00
feat(rake-fast): show task descriptions in autocomplete (#11653)
This commit is contained in:
parent
693e3dcc44
commit
dab09cc0ee
1 changed files with 36 additions and 3 deletions
|
@ -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 () {
|
||||
[[ ! -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 () {
|
||||
|
@ -20,7 +43,14 @@ _tasks_changed () {
|
|||
}
|
||||
|
||||
_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 () {
|
||||
|
@ -29,7 +59,10 @@ _rake () {
|
|||
echo "\nGenerating .rake_tasks..." >&2
|
||||
_rake_generate
|
||||
fi
|
||||
compadd $(cat .rake_tasks)
|
||||
local -a rake_options
|
||||
rake_options=("${(@f)$(cat .rake_tasks)}")
|
||||
shift rake_options
|
||||
_describe 'rake tasks' rake_options
|
||||
fi
|
||||
}
|
||||
compdef _rake rake
|
||||
|
|
Loading…
Reference in a new issue