.bash_completion.d/pip
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 29 Mar 2023 23:42:06 +0300
changeset 1018 831e2c1bf980
parent 729 3808bb55f8bb
permissions -rw-r--r--
Completed migration from ~/devel to ~/work.

# -*- mode: sh; sh-shell-file: bash -*-

_pip()
{
  local _cmds='install uninstall freeze list show search wheel help'
  local _acts='switch ignore wipe backup'
  local _opts='-h --help -v --verbose -V --version -q --quiet --proxy --timeout'
  local _index_opts='-i --index-url --extra-index-url --no-index -f --find-links --allow-external --allow-all-external --allow-unverified --process-dependency-links'
  local _install_opts='-e --editable -U --upgrade --force-reinstall -I --ignore-installed --no-deps --no-install --no-download \
--install-option --user --egg --compile --no-compile --no-use-wheel --pre --no-clean \
-e --editable -b --build -t --target -d --download --download-cache \
-r --requirement'
  local _uninstall_opts='-y --yes -r --requirement'
  local _list_opts='-o --outdated -u --uptodate -e --editable -l --local --pre'
  local _freeze_opts='-f --find-links -l --local'
  local _search_opts='--index'
  local _show_opts='--index'
  local _wheel_opts='--no-use-wheel --build-option --no-deps --global-option --pre --no-clean \
-w --wheel-dir --download-cache -b --build
-r, --requirement'
  local cur
  cur=${COMP_WORDS[COMP_CWORD]}
  if [[ $COMP_CWORD = 1 ]]; then
    COMPREPLY=( $(compgen -W '$_cmds'  -- "$cur") )
    return 0
  fi
  local first prev
  first=${COMP_WORDS[1]}
  prev=${COMP_WORDS[COMP_CWORD-1]}
  case "$prev" in
    --cert|--log|--log-file)
      compopt -o default; COMPREPLY=()
      return 0 ;;
    --exists-action)
      COMPREPLY=( $(compgen -W  '$_acts' -- "$cur") )
      return 0 ;;
  esac
  case $first in
    install)
      case $prev in
        -e|--editable|-b|--build|-t|--target|-d|--download|--download-cache)
          compopt -o dirnames; COMPREPLY=()
          return 0 ;;
        -r|--requirement)
          compopt -o default; COMPREPLY=()
          return 0 ;;
      esac
      COMPREPLY=( $(compgen -W '$_install_opts $_opts $_index_opts'  -- "$cur") )
      return 0 ;;
    uninstall)
      case $prev in
        -r|--requirement)
          compopt -o default; COMPREPLY=()
          return 0 ;;
      esac
      COMPREPLY=( $(compgen -W '$_uninstall_opts $_opts'  -- "$cur") )
      return 0 ;;
    list)
      COMPREPLY=( $(compgen -W '$_list_opts $_opts $_index_opts'  -- "$cur") )
      return 0 ;;
    freeze)
      case $prev in
        -r|--requirement)
          compopt -o default; COMPREPLY=()
          return 0 ;;
      esac
      COMPREPLY=( $(compgen -W '$_freeze_opts $_opts'  -- "$cur") )
      return 0 ;;
    search)
      COMPREPLY=( $(compgen -W '$_search_opts $_opts'  -- "$cur") )
      return 0 ;;
    show)
      COMPREPLY=( $(compgen -W '$_show_opts $_opts'  -- "$cur") )
      return 0 ;;
    wheel)
      case $prev in
        -w|--wheel-dir|--download-cache|-b|--build)
          compopt -o dirnames; COMPREPLY=()
          return 0 ;;
        -r|--requirement)
          compopt -o default; COMPREPLY=()
          return 0 ;;
      esac
      COMPREPLY=( $(compgen -W '$_wheel_opts $_opts $_index_opts'  -- "$cur") )
      return 0 ;;
  esac
  COMPREPLY=( $(compgen -W '$_opts'  -- "$cur") )
  return 0
} &&
    complete -F _pip pip pip2 pip2.5 pip2.6 pip2.7 pip2.8