about summary refs log tree commit diff
path: root/Completion/Unix/Command/_bogofilter
blob: 3e73d5d263ab59be299aa17e8e3a6d0f98eb004f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#compdef bogoutil

local ret bogotokens

_bogoutil_caching_policy () {

  # rebuild if cache is more than a week old
  oldp=( "$1"(mw+1) )
  (( $#oldp )) && return 0

  return 1
}

_bogofilter() {
  _arguments -C \
  	'-v[verbose]' \
  	'-n[replace non-ASCII characters]' \
  	'-D[redirect debug output to stdout]' \
  	'-a[acceptable token age]:date or day count' \
  	'-c[acceptable count]:count threshold' \
  	'-s[acceptable size range]:min-max range' \
  	'-y[date for when unknown]:date' \
  	'-I[input file]:input file:_files' \
  	'-x[debug flags]:debug flags:' \
  	'-d[print contents of db]:database:_files -g "*.db"' \
  	'-l[load file into db]:textfile:_files' \
  	'-m[perform maintenance functions]' \
  	'-w[display token information]:database file or directory:_files' \
  	'-p[display token probability information]:database file or directory:_files' \
	'-C[verify database]:database:_files -/' \
  	'-H[print histogram]' \
  	'(-f -F -P -R)-r[recalculate ROBX]:database:_files -/' \
  	'(-f -F -P -r)-R[recalculate and save ROBX]:database:_files -/' \
	'(-F -P -r -R)-f[run regular recovery]:database:_files -/' \
	'(-f -P -r -R)-F[run catastrophic recovery]:database:_files -/' \
	'(-f -F -r -R)-P[checkpoint database]:database:_files -/' \
	'(-f -F -r -R -P)--remove-environment:database:_files -/' \
  	'-h[help]' \
  	'-V[version]' \
  	'*:tokens:->tokens' && ret=0
  
  zstyle -s ":completion:${curcontext}:" cache-policy update_policy
  if [[ -z "$update_policy" ]]; then
    zstyle ":completion:${curcontext}:" cache-policy _bogoutil_caching_policy
  fi
  
  case $state in
  	(tokens)
  	if ( [[ -z "$bogotokens" ]] || _cache_invalid bogotokens ) &&
  	  ! _retrieve_cache bogotokens; then
  	  bogotokens=(${${(f)"$(_call_program bogoutil bogoutil -d ~/.bogofilter/wordlist.db -c 50)"}%% *})
  	  _store_cache bogotokens bogotokens
  	else
  	  :
  	fi
  	  _wanted tokens expl "token" \
  	     compadd -a bogotokens
  	;;
  esac
}

_bogofilter "$@"