Added Bash completion for winget.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sun, 12 Jun 2022 19:01:39 +0300
changeset 1001 b4df956c3d52
parent 1000 e3e1539cafa9
child 1002 a9073ca0921b
Added Bash completion for winget.
.bash_completion.d/winget
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.bash_completion.d/winget	Sun Jun 12 19:01:39 2022 +0300
@@ -0,0 +1,51 @@
+# -*- 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