.bash_completion.d/scoop
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 01 Jan 2024 20:53:49 +0200
changeset 1039 78cdb4a057e3
parent 1019 ee5840caf22c
permissions -rw-r--r--
Create symlink from ~/.bash_profile for login shell to activate my ~/.bashrc.

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


_scoop() {
  local tasks='alias      (Manage scoop aliases)
bucket     (Manage Scoop buckets)
cache      (Show or clear the download cache)
cat        (Show content of specified manifest)
checkup    (Check for potential problems)
cleanup    (Cleanup apps by removing old versions)
config     (Get or set configuration values)
create     (Create a custom app manifest)
depends    (List dependencies for an app)
download   (Download apps in the cache folder and verify hashes)
export     (Exports (an importable) list of installed apps)
help       (Show help for a command)
hold       (Hold an app to disable updates)
home       (Opens the app homepage)
info       (Display information about an app)
install    (Install apps)
list       (List installed apps)
prefix     (Returns the path to the specified app)
reset      (Reset an app to resolve conflicts)
search     (Search available apps)
shim       (Manipulate Scoop shims)
status     (Show status and check for new app versions)
unhold     (Unhold an app to enable updates)
uninstall  (Uninstall an app)
update     (Update apps, or Scoop itself)
virustotal (Look for apps hash on virustotal.com)
which      (Locate a shim/executable)'
  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
    cat|depends|download|export|hold|home|info|install|prefix|reset|status|unhold|uninstall|update|virustotal|which)
      local dir=`command -v scoop`
      dir=${dir%/shims/*}/buckets
      [[ -d "$dir" ]] || return
      local olddir="$PWD"
      cd $dir
      local -a jsons=( */bucket/"$cur"*.json )
      local -a pkgs=( "${jsons[@]##*/}" )
      COMPREPLY=( "${pkgs[@]%.json}" )
      cd "$olddir"
      return
    ;;
    bucket)
      if [[ $COMP_CWORD = 2 ]]; then
        COMPREPLY=( $(compgen -W 'add list known rm' -- "$cur") )
        return
      fi
      local subcmd="${COMP_WORDS[2]}"
      case "$subcmd" in
        list|known)
          COMPREPLY=( )
          return
          ;;
        add|rm)
          local -a buckets=( `scoop bucket known` )
          local cr=$'\r'
          buckets=( "${buckets[@]/$cr/}" )
          COMPREPLY=( $(compgen -W '${buckets[@]}' -- "$cur") )
          return
          ;;
      esac
  esac
}

complete -F _scoop scoop