.bash_completion.d/scoop
author Oleksandr Gavenko <gavenkoa@gmail.com>
Thu, 23 Feb 2023 00:59:27 +0200
changeset 1016 8ba787ff5ab8
parent 1008 86630b8cd151
child 1019 ee5840caf22c
permissions -rw-r--r--
Removed .npmrc, HOME in Cygwin & running npm outside of Cygwin results in duplicating cache (in Cygwin HOME & in APPDATA).

# -*- 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
    ;;
  esac
}

complete -F _scoop scoop