.bash_completion.d/scoop
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 29 Mar 2023 23:42:06 +0300
changeset 1018 831e2c1bf980
parent 1008 86630b8cd151
child 1019 ee5840caf22c
permissions -rw-r--r--
Completed migration from ~/devel to ~/work.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1000
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
# -*- mode: sh; sh-shell-file: bash -*-
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
_scoop() {
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
  local tasks='alias      (Manage scoop aliases)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
bucket     (Manage Scoop buckets)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
cache      (Show or clear the download cache)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
cat        (Show content of specified manifest)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
checkup    (Check for potential problems)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
cleanup    (Cleanup apps by removing old versions)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
config     (Get or set configuration values)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
create     (Create a custom app manifest)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
depends    (List dependencies for an app)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
download   (Download apps in the cache folder and verify hashes)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
export     (Exports (an importable) list of installed apps)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
help       (Show help for a command)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
hold       (Hold an app to disable updates)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
home       (Opens the app homepage)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
info       (Display information about an app)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
install    (Install apps)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
list       (List installed apps)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
prefix     (Returns the path to the specified app)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
reset      (Reset an app to resolve conflicts)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
search     (Search available apps)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
shim       (Manipulate Scoop shims)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
status     (Show status and check for new app versions)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
unhold     (Unhold an app to enable updates)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
uninstall  (Uninstall an app)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
update     (Update apps, or Scoop itself)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
virustotal (Look for apps hash on virustotal.com)
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    31
which      (Locate a shim/executable)'
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    32
  local cur prev
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
  cur=${COMP_WORDS[COMP_CWORD]}
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
  [[ $COMP_CWORD -gt 1 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
  if [[ $COMP_CWORD = 1 ]]; then
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
    local OIFS="$IFS"
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
    local IFS=$'\n'
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
    COMPREPLY=( $(compgen -W '$tasks' -- "$cur") )
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
    if [[ ${#COMPREPLY[@]} -le 1 ]]; then
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
      COMPREPLY=( ${COMPREPLY[0]%% *} )
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
    fi
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
    IFS=$OIFS
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
    return
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
  fi
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47
  local cmd="${COMP_WORDS[1]}"
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
  case "$cmd" in
1008
86630b8cd151 Added which to scoop completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1000
diff changeset
    49
    cat|depends|download|export|hold|home|info|install|prefix|reset|status|unhold|uninstall|update|virustotal|which)
1000
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50
      local dir=`command -v scoop`
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    51
      dir=${dir%/shims/*}/buckets
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    52
      [[ -d "$dir" ]] || return
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
      local olddir="$PWD"
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    54
      cd $dir
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    55
      local -a jsons=( */bucket/"$cur"*.json )
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    56
      local -a pkgs=( "${jsons[@]##*/}" )
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    57
      COMPREPLY=( "${pkgs[@]%.json}" )
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    58
      cd "$olddir"
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    59
      return
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    60
    ;;
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    61
  esac
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    62
}
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    63
e3e1539cafa9 Added bash autocompletion for Scoop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    64
complete -F _scoop scoop