Skip to content

Commit

Permalink
Merge pull request ohmyzsh#1312 from koenpunt/fixes_cap_plugin
Browse files Browse the repository at this point in the history
updated cap plugin to use `cap -T` instead of `cap show_tasks`
  • Loading branch information
robbyrussell committed Oct 9, 2012
2 parents c5a8905 + 9a4fac1 commit 6d4b0c6
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions plugins/cap/cap.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
function _cap_does_task_list_need_generating () {
if [ ! -f .cap_tasks~ ]; then return 0;
stat -f%m . > /dev/null 2>&1
if [ "$?" = 0 ]; then
stat_cmd=(stat -f%m)
else
stat_cmd=(stat -L --format=%y)
fi

# Cache filename
_cap_show_undescribed_tasks=0

# Cache filename
_cap_task_cache_file='.cap_task_cache'

_cap_get_task_list () {
if [ ${_cap_show_undescribed_tasks} -eq 0 ]; then
cap -T | grep '^cap' | cut -d " " -f 2
else
cap -vT | grep '^cap' | cut -d " " -f 2
fi
}

_cap_does_task_list_need_generating () {

if [ ! -f ${_cap_task_cache_file} ]; then return 0;
else
accurate=$(stat -f%m .cap_tasks~)
changed=$(stat -f%m config/deploy.rb)
accurate=$($stat_cmd $_cap_task_cache_file)
changed=$($stat_cmd config/deploy.rb)
return $(expr $accurate '>=' $changed)
fi
}

function _cap () {
if [ -f config/deploy.rb ]; then
if _cap_does_task_list_need_generating; then
echo "\nGenerating .cap_tasks~..." > /dev/stderr
cap show_tasks -q | cut -d " " -f 1 | sed -e '/^ *$/D' -e '1,2D'
> .cap_tasks~
_cap_get_task_list > ${_cap_task_cache_file}
fi
compadd `cat .cap_tasks~`
compadd `cat ${_cap_task_cache_file}`
fi
}

compctl -K _cap cap
compdef _cap cap

0 comments on commit 6d4b0c6

Please sign in to comment.