aboutsummaryrefslogtreecommitdiffstats
path: root/src/_port
blob: db39c1f80ec6b28fc09a7590059c438861181a3f (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
#compdef port
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for MacPorts (http://www.macports.org).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * Matt Cable <wozz@wookie.net>
#  * Sorin Ionescu <sorin.ionescu@gmail.com>
#  * Aljaž Srebrnič <a2piratesoft@gmail.com>
#
# ------------------------------------------------------------------------------

_port_select() {
  if (( CURRENT == 3 )); then
    _describe 'Port select options' select_options
  elif (( CURRENT == 4 )); then
    local select_group
    select_group=()
    for f in $port_prefix/etc/select/*; do
      select_group+=$(basename $f)
    done
    _describe "Port select groups" select_group
  elif [[ $CURRENT -eq 5 && $words[3] == '--set' ]]; then
    local select_variants
    select_variants=("${(f)$(port select --list $words[4] | sed -e '1 d' -e 's/^[ \t]*//' -e 's/ (active)$//')}")
    _describe "Port select group $words[4] variants" select_variants
  fi
}

_port() {
  # Variables for _argument
  typeset -A opt_args
  local   context state state_descr line

  local   actions pseudo_common pseudo_advanced select_options port_prefix

  port_prefix=$(which port | sed 's|/bin/port||')

  actions=( activate archive archivefetch build cat cd
  checksum clean configure contents deactivate dependents deps
  destroot dir distcheck distfiles dmg dpkg echo edit exit
  extract fetch file gohome help info install installed lint list
  livecheck load location log logfile mdmg mirror mpkg notes
  outdated patch pkg platform portpkg provides quit rdependents
  rdeps rev-upgrade rpm search select selfupdate setrequested space
  srpm submit sync test unarchive uninstall unload unsetrequested
  upgrade url usage variants version work )

  pseudo_common=(all current active inactive actinact installed uninstalled outdated
  obsolete requested unrequested leaves)

  pseudo_advanced=('variants:' 'variant:' 'description:' 'depends:'
  'depends_lib:' 'depends_run:' 'depends_build:' 'depends_fetch:' 'depends_extract:'
  'portdir:' 'homepage:' 'epoch:' 'platforms:' 'platform:' 'name:' 'long_description:'
  'maintainers:' 'maintainer:' 'categories:' 'category:' 'version:' 'revision:' 'license:')

  select_options=(
  '--list:List available versions for the group'
  '--set:Select the given version for the group'
  '--show:Show which version is currently selected for the group \(default if none given\)'
  )

  _arguments -s -C \
    '-v[verbose mode (generate verbose messages)]' \
    '-d[debug mode (generate debugging messages, implies -v)]' \
    '-q[quiet mode (suppress messages)]' \
    "-n[don't upgrade dependencies (affects upgrade and install)]" \
    "-R[also upgrade dependents (only affects upgrade) - note that this does not upgrade dependents' dependencies]" \
    '-u[uninstall non-active ports when upgrading and uninstalling]' \
    '-f[force mode (ignore state file)]' \
    '-o[honor state files even if the Portfile has been modified since (called -o because it used to mean "older")]' \
    '-s[source-only mode (build and install from source, do not attempt to fetch binary archives)]' \
    '-b[binary-only mode (build and install from binary archives, ignore source, abort if no archive available)]' \
    '-c[autoclean mode (execute clean after install)]' \
    "-k[keep mode (don't autoclean after install)]" \
    '-D[specify portdir]' \
    '-F[Read and process the file of commands specified by the argument.]' \
    '-p[Despite any errors encountered, proceed to process multiple ports and commands.]' \
    '-y[Perform a dry run.]' \
    '-t[enable trace mode debug facilities on platforms that support it (Mac OS X).]' \
    "1:Port actions:($actions)" \
    '*:extra:->extra' \
    && return 0

  case "$state" in
    extra)
      case "$words[2]" in
        provides)
          _files
          ;;
        search)
          _guard '^--*' 'pattern'
          ;;
        help)
          _describe -t actions 'Port actions' actions
          ;;
        select)
          _call_function - _port_select
          ;;
        contents|deactivate|setrequested|space|uninstall|unsetrequested)
          # Cache the list of all ports.
          if (( ! $+_installed_ports )); then
            _installed_ports=$(_call_program path-installed "port installed | cut -d ' ' -f 3")
          fi
          _alternative \
            "ports:Installed ports:($_installed_ports)" \
            "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
            "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
          ;;
        *)
          # Cache the list of all ports.
          if (( ! $+_all_ports )); then
            _all_ports=$(_call_program path-all "port echo all")
          fi
          _alternative \
            "ports:Available ports:($_all_ports)" \
            "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
            "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
          ;;
      esac
      ;;
  esac
}

_port "$@"