Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 104 lines (91 sloc) 2.833 kb
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
#compdef cower

typeset -A opt_args

_cower_opts_commands=(
  '-d[Download target(s)]'
  '-i[Show info for target(s)]'
  '-m[Show packages maintained by target(s)]'
  '-s[Search for target(s)]'
  '-u[Check for updates against AUR]'
  '-h[Display usage]'
)

_cower_opts_general=(
  '-f[Overwrite existing files when downloading]'
  '*--ignore[Ignore a package upgrade]:package:
          _cower_completions_installed_packages'
  '*--ignorerepo[Ignore some or all binary repos]:repositories:
          _cower_completions_repositories'
  '--nossl[Do not use https connections]'
  '-t[Specify an alternate download directory]:target:_files -/'
  '--threads[Limit number of threads created]:number of threads'
  '--timeout[Specify connection timeout in seconds]:timeout'
)

_cower_opts_output=(
  '-c[Use colored output]'
  '--debug[Show debug output]'
  '-q[Output less]'
  '-v[Output more]'
)

_cower_action_none() {
  _arguments -s -w : \
    "$_cower_opts_commands[@]"
}

# provides completions for installed packages
_cower_completions_installed_packages() {
  local -a cmd packages packages_long
  packages_long=(/var/lib/pacman/local/*(/))
  packages=( ${${packages_long#/var/lib/pacman/local/}%-*-*} )
  compadd "$@" -a packages
}

_cower_completions_repositories() {
  local -a cmd repositories
  repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
  # Uniq the array
  typeset -U repositories
  compadd "$@" -a repositories
}

_cower_completions_aur() {
  local -a aur_packages
  aur_packages=($(_call_program packages $service -sq $words[CURRENT] 2>/dev/null))
  compadd "$@" -a aur_packages
}

_cower_completions_format() {
  arguments=(%c %d %i %l %n %o %p %t %u %v %%)
  if [[ $words = *-i*i* ]]; then
    arguments+=(%C %D %M %O %P %R)
  fi
  compadd "$@" -a arguments
}

_cower() {
  case $words[2] in
    -[ms]*) _arguments -s -w : \
      "$_cower_opts_general[@]" \
      "$_cower_opts_output[@]" \
      '--format[Print package output according to format string]:string:
          _cower_completions_format'
      ;;
    -i*) _arguments -s -w : \
      "$_cower_opts_general[@]" \
      "$_cower_opts_output[@]" \
      '*-i[Show more info]' \
      '*:package:_cower_completions_aur' \
      '--listdelim[Change list format delimeter]' \
      '--format[Print package output according to format string]:string:
          _cower_completions_format'
      ;;
    -d*) _arguments -s -w : \
      "$_cower_opts_general[@]" \
      "$_cower_opts_output[@]" \
      '*-d[Download AUR dependencies]' \
      '*:package:_cower_completions_aur'
      ;;
    -u*) _arguments -s -w : \
      "$_cower_opts_general[@]" \
      "$_cower_opts_output[@]" \
      '*-d[Download updates]'
      ;;
    -) _cower_action_none ;;
    *) return 1 ;;
  esac
}

_cower "$@"

# vim: set et sw=2 ts=2 ft=zsh :
Something went wrong with that request. Please try again.