.bash_completion.d/winget
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 28 Nov 2022 23:08:33 +0200
changeset 1005 2b1061d35183
parent 1001 b4df956c3d52
permissions -rw-r--r--
Decided transition from ~/devel to ~/work.

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


_winget() {
  local tasks='install  (Installs the given package)
show     (Shows information about a package)
source   (Manage sources of packages)
search   (Find and show basic info of packages)
list     (Display installed packages)
upgrade  (Upgrades the given package)
uninstall (Uninstalls the given package)
hash     (Helper to hash installer files)
validate (Validates a manifest file)
settings (Open settings)
features (Shows the status of experimental features)
export   (Exports a list of the installed packages)
import   (Installs all the packages in a file)'
  local cur prev
  cur=${COMP_WORDS[COMP_CWORD]}
  [[ $COMP_CWORD -gt 1 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}

  if [[ $COMP_CWORD = 1 ]]; then
    local OIFS="$IFS"
    local IFS=$'\n'
    COMPREPLY=( $(compgen -W '$tasks' -- "$cur") )
    if [[ ${#COMPREPLY[@]} -le 1 ]]; then
      COMPREPLY=( ${COMPREPLY[0]%% *} )
    fi
    IFS=$OIFS
    return
  fi

  local cmd="${COMP_WORDS[1]}"
  case "$cmd" in
    source)
      local OIFS="$IFS"
      local IFS=$'\n'
      local tasks='add    (Add a new source)
list   (List current sources)
update (Update current sources)
remove (Remove current sources)
reset  (Reset sources)
export (Export current sources)'
      COMPREPLY=( $(compgen -W '$tasks' -- "$cur") )
      IFS=$OIFS
      return
    ;;
  esac
}

complete -F _winget winget