cap.plugin.zsh 871 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 () {
Koen Punt's avatar
Koen Punt committed
15
  if [ ${_cap_show_undescribed_tasks} -eq 0 ]; then
16
17
18
19
20
21
22
23
24
    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;
25
  else
26
27
    accurate=$($stat_cmd $_cap_task_cache_file)
    changed=$($stat_cmd config/deploy.rb)
28
29
30
31
32
33
34
    return $(expr $accurate '>=' $changed)
  fi
}

function _cap () {
  if [ -f config/deploy.rb ]; then
    if _cap_does_task_list_need_generating; then
35
      _cap_get_task_list > ${_cap_task_cache_file}
36
    fi
37
    compadd `cat ${_cap_task_cache_file}`
38
39
40
  fi
}

41
compdef _cap cap