about summary refs log tree commit diff
path: root/Completion/BSD/Command/_bsd_pkg
blob: 81b187134e7013b1ee6a5a61b6f2e03a1f22698a (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
168
169
170
171
172
173
174
175
176
#compdef pkg_add pkg_delete pkg_info

(( $+functions[_bsd_pkg_pkgfiles] )) ||
_bsd_pkg_pkgfiles() {
  local ret=1 paths portsdir pkgsdir

  case $OSTYPE in
  netbsd*)
    portsdir=/usr/pkgsrc
    ;;
  *)
    portsdir=${PORTSDIR:-/usr/ports}
    ;;
  esac

  pkgsdir=${PACKAGES:-$portsdir/packages}/All

  paths=( "${(@)${(@s.:.)PKG_PATH}:#}" )
  _files "$@" -g '*.t[bg]z' && ret=0
  (( $#path )) && _files "$@" -W paths -g '*.t[bg]z' && ret=0
  compadd "$@" - $pkgsdir/*.t[bg]z && ret=0

  return ret
}

(( $+functions[_bsd_pkg_pkgs] )) ||
_bsd_pkg_pkgs() {
  compadd "$@" - ${PKG_DBDIR:-/var/db/pkg}/*(/:t)
}

(( $+functions[_bsd_pkg_pkgs_and_files] )) ||
_bsd_pkg_pkgs_and_files() {
  local ret=1

  if (( $words[(I)-*F*] )); then
    _files "$@" && ret=0
  else
    _bsd_pkg_pkgs "$@" && ret=0
  fi

  return ret
}

_bsd_pkg() {
  local flags

  case "$service" in
  pkg_add)
    flags=(
      '-f[force installation]'
      '-I[don'\''t execute installation scripts]'
      '-M[run in master mode]'
      '-n[don'\''t really install packages]'
      '-p[specify prefix]:prefix directory:_files -/'
      '-R[don'\''t record]'
      '-S[run in slave mode]'
      '-t[specify mktemp template]:mktemp template:_files -/'
      '-v[be verbose]'
    )

    case "$OSTYPE" in
    freebsd*)
      flags=(
        $flags[@]
        '-r[fetch from remote site]'
      )
      ;;
    netbsd*)
      flags=(
	$flags[@]
	'-u[update]'
	'-V[show version and exit]'
      )
      ;;
    esac

    _arguments -s \
      $flags[@] \
      '*:package to install:_bsd_pkg_pkgfiles'
    ;;

  pkg_delete)
    flags=(
      '-D[don'\''t execute deinstallation scripts]'
      '-d[remove empty directories]'
      '-f[force deinstallation]'
      '-n[don'\''t really deinstall packages]'
      '-p[specify prefix]:prefix directory:_files -/'
      '-v[be verbose]'
    )

    case "$OSTYPE" in
    freebsd*)
      flags=(
        $flags[@]
	'(:)-a[delete all installed packages]'
        '-G[do not expand glob patterns]'
	'-i[be interactive]'
        '-r[delete recursively]'
        '-x[use regular expression]'
      )
      ;;
    netbsd*)
      flags=(
	$flags[@]
	'(:)-a[delete all installed packages]'
	'-F[specify each package by an installed file]'
	'-i[be interactive]'
	'-O[only delete the package'\''s entries]'
        '-R[delete upward recursively]'
        '-r[delete recursively]'
	'-V[show version and exit]'
      )
      ;;
    esac

    _arguments -s \
      $flags[@] \
      '(-a)*:package name:_bsd_pkg_pkgs_and_files'
    ;;

  pkg_info)
    flags=(
      '(:)-a[show all installed packages]'
      '-c[show comment fields]'
      '-D[show install-message files]'
      '-d[show long descriptions]'
      '-e[test if package is installed]:package name:_bsd_pkg_pkgs'
      '-f[show packing list instructions]'
      '-I[show index lines]'
      '-i[show install scripts]'
      '-k[show deinstall scripts]'
      '-L[show full pathnames of files]'
      '-l[specify prefix string]:prefix string:'
      '-m[show mtree files]'
      '-p[show installation prefixes]'
      '-q[be quiet]'
      '-R[show list list of installed requiring packages]'
      '-r[show requirements scripts]'
      '-v[be verbose]'
    )

    case "$OSTYPE" in
    freebsd*)
      flags=(
        $flags[@]
        '-G[do not expand glob patterns]'
	'-g[show files that'\''s modified]'
	'-o[show origin]'
	'-s[show total size occupied by each package]'
	'-t[specify mktemp template]:mktemp template:_files -/'
	'*-W[show which package the file belongs to]:file:_files'
	'-x[use regular expression]'
      )
      ;;
    netbsd*)
      flags=(
	$flags[@]
	'-B[show build information]'
	'-b[show RCS Id strings]'
	'-F[specify each package by an installed file]'
	'-S[show total size occupied by each package and its dependents]'
	'-s[show total size occupied by each package]'
	'-V[show version and exit]'
      )
      ;;
    esac

    _arguments -s \
      $flags[@] \
      '(-a)*:package name:_bsd_pkg_pkgs_and_files'
    ;;
  esac
}

_bsd_pkg "$@"