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 42 lines (32 sloc) 1.456 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
#!/bin/bash

_cower() {
  local i cur prev opts ng

  _get_comp_words_by_ref cur prev

  # nullglob avoids problems when no results are found
  shopt -q nullglob || { shopt -s nullglob; ng=1; }

  opts="-d --download -i --info -m --msearch -s --search -u --update -c --color
        -f --force --format -h --help --ignore --ignorerepo --listdelim --nossl
        -q --quiet -t --target --threads -v --verbose --debug"

  n=${#COMP_WORDS[@]}

  if [[ "$cur" = -* ]]; then # options
    COMPREPLY=($(compgen -W "$opts" -- $cur))
  elif [[ "$prev" = @(-*t|--target) ]]; then # directories (taken from _cd)
    compgen -f /non-existing-dir/ >/dev/null
    _filedir -d
    if (( ${#COMPREPLY[@]} == 1 )); then
      i=${COMPREPLY[0]}
      [[ "$i" = $cur && "$i" != */ ]] && COMPREPLY[0]="${i}/"
    fi
  elif [[ "$prev" = --ignore ]]; then
    COMPREPLY=($(compgen -W "$(pacman -Qq)" -- $cur))
  elif [[ "$prev" = --ignorerepo ]]; then
    COMPREPLY=($(compgen -W "$(sed '/^\[\(.*\)\]$/!d;s//\1/;/options/d' /etc/pacman.conf)" -- $cur))
  elif [[ "${COMP_WORDS[@]:1:n-2}" = *-@(!(-*)@(u)*|-update)* ]]; then # local packages
    COMPREPLY=($(compgen -W "$(pacman -Qqm)" -- $cur))
  elif [[ "${COMP_WORDS[@]:1:n-2}" = *-@(!(-*)@(d|i)*|-download|-info)* ]]; then # aur packages
    COMPREPLY=($(compgen -W "$("${COMP_WORDS[0]}" -sq -- ^$cur 2>/dev/null)" -- $cur))
  fi

  # restore nullglob setting
  [[ $ng ]] && shopt -u nullglob

}

complete -F _cower cower
Something went wrong with that request. Please try again.