about summary refs log tree commit diff
path: root/Completion/Darwin/Command/_fink
blob: 27ca3740c310cd37418df7bc9acb2af5ea591476 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#compdef fink

_fink_get_packages_with_cache(){
  local cache_policy
  zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  if [[ -z "$cache_policy" ]]; then
    zstyle ":completion:${curcontext}:" cache-policy _finkpkgs_caching_policy
  fi

  typeset -g -a _fink_pkgs
  local expl

  if ( (( #_fink_pkgs == 0 )) || _cache_invalid finkpkgs) \
       && ! _retrieve_cache finkpkgs; then
    _fink_pkgs=(${(f)"$(
      command fink list --tab \
      | command grep -v '\[virtual package\]' \
      | command sed 's/^   / n /' \
      | command cut -f1,2
    )"})
    _store_cache finkpkgs _fink_pkgs
  fi

  if (( # > 0 )); then
    local i
    for i in "$@"; do
      case "$i" in
        -i) packages+=(${${(M)_fink_pkgs:#?i?*}#*	}) ;;
        -o) packages+=(${${(M)_fink_pkgs:#(i)*}#*	}) ;;
        -n) packages+=(${${(M)_fink_pkgs:# n *}#*	}) ;;
      esac
    done
  else
    packages=(${_fink_pkgs#*	})
  fi
}

_fink_get_packages_without_cache(){
  local expl

  packages=(${(f)"$(
    command fink list -t "$@" "$PREFIX" \
    | command grep -v '\[virtual package\]' \
    | command cut -f2
  )"})
}

_fink_get_packages(){
  # variable packages will be set
  if zstyle -t ":completion:${curcontext}:" use-cache; then
    _fink_get_packages_with_cache "$@"
  else
    _fink_get_packages_without_cache "$@"
  fi
}

_finkpkgs_caching_policy(){
  local -a oldp
  oldp=( "$1"(Nmw+1) )
  (( $#oldp )) ||
    [[ /sw/var/cache/apt/pkgcache.bin -nt "$1" ]] ||
    [[ /sw/var/lib/dpkg/available -nt "$1" ]]
}

_fink(){
  local -a _1st_arguments
  _1st_arguments=(
    'install:install or update packages'
    'remove:remove packages'
    'purge:remove packages and configuration files'
    'update-all:update all installed packages to the latest version'
    'list:search package name or conditions and list'
    'apropos:search package descriptions or conditions and list'
    'describe:display a description of the package'
    'fetch:download package source files'
    'fetch-all:downloads all package source files'
    'fetch-missing:download all missing package source files'
    'build:build .deb packages'
    'rebuild:rebuild .deb packages'
    'reinstall:reinstall packages'
    'configure:rerun the fink configuration process'
    'selfupdate:upgrade to a new fink release'
    'validate:validate files'
    'scanpackages:call dpkg-scanpackages'
    'checksums:validate the MD5 digest of all tarballs'
    'cleanup:removes obsolete package files'
  )

  local context state line expl
  local -A opt_args

  _arguments \
    '(-h --help)'{-h,--help}'[display help text]' \
    '(-q --quiet)'{-q,--quiet}'[causes fink to be less verbose]' \
    '(-V --version)'{-V,--version}'[display version information]' \
    '(-v --verbose)'{-v,--verbose}'[causes fink to be more verbose]' \
    '(-y --yes)'{-y,--yes}'[assume default answer for interactive questions]' \
    '*:: :->subcmds' && return 0

  if (( CURRENT == 1 )); then
    _describe -t commands "fink subcommand" _1st_arguments
    return
  fi

  local -a packages

  case "$words[1]" in
    install|update|enable|activate|use)
      _fink_get_packages -n -o
      _wanted packages expl 'not installed or outdated fink package' compadd -a packages ;;
    remove|disable|deactivate|unuse|delete|purge)
      _fink_get_packages -i
      _wanted packages expl 'installed package' compadd -a packages ;;
    #update-all)
    list)
      _arguments \
	'(-t --tab)'{-t,--tab}'[outputs list with tabs as field delimiter]' \
        '(-i --installed)'{-i,--installed}'[packages currently installed]' \
        '(-u --uptodate)'{-u,--uptodate}'[packages up to date]' \
        '(-o --outdate)'{-o,--outdated}'[packages newer version is available]' \
        '(-n --notinstalled)'{-n,--notinstalled}'[packages not installed]' \
	'(-b --buildonly)'{-b,--buildonly}'[packages Build Only Depends]' \
	'(-s --section)'{-s=,--section=}'[sections]:section name' \
	'(-m --maintainer)'{-m=,--maintainer=}'[maintainer]:maintainer name' \
	--tree='[tree]:tree name' \
	'(-w --width)'{-w=,--width=}'[width of display]:number or "auto"' \
	'(1 : -)'{-h,--help}'[display help text]' \
	'1: :->pkgs' && return 0

        if [[ "$state" == pkgs ]]; then
          _fink_get_packages
          _wanted packages expl 'package name hint' compadd -a packages
        fi ;;
    apropos)
      _arguments \
        '(-t --tab)'{-t,--tab}'[output the list with tabs as field delimiter]' \
        '(-w --width)'{-w=,--width=}'[width of display]:number or "auto"' \
        '(1 : -)'{-h,--help}'[display help text]' \
        '1: :->pkgs' && return 0
        
        if [[ "$state" == pkgs ]]; then
          _fink_get_packages
          _wanted packages expl 'package hint' compadd -a packages
        fi ;;
    describe|desc|description|info)
      _fink_get_packages
      _wanted packages expl 'package' compadd -a packages ;;
    #fetch)
    #fetch-all)
    fetch-missing)
      _arguments \
        '(-i --ignore-restrictive)'{-i,--ignore-restrictive}'[do not fetch packages that are "License: Restrictive"]' ;;
    #build)
    rebuild|reinstall)
      _fink_get_packages
      _wanted packages expl 'package' compadd -a packages ;;
    #configure)
    #selfupdate)
    validate|check)
      _wanted files expl 'finkinfo file' _files -g \*.info ;;
    #scanpackages)
    #checksums)
    #cleanup)
  esac
}

_fink "$@"