Added bash autocompletion for Scoop.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Thu, 09 Jun 2022 16:01:09 +0300
changeset 1000 e3e1539cafa9
parent 999 fb93b077af25
child 1001 b4df956c3d52
Added bash autocompletion for Scoop.
.bash_completion.d/scoop
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.bash_completion.d/scoop	Thu Jun 09 16:01:09 2022 +0300
@@ -0,0 +1,64 @@
+# -*- 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)
+      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