Basic wsl Bash completion.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sun, 10 Dec 2023 22:23:26 +0200
changeset 1035 1c38c02cfe9e
parent 1034 7353d0eeff27
child 1036 5b1ba85724fd
Basic wsl Bash completion.
.local/share/bash-completion/completions/wsl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.local/share/bash-completion/completions/wsl	Sun Dec 10 22:23:26 2023 +0200
@@ -0,0 +1,39 @@
+# -*- mode: sh; sh-shell-file: bash -*-
+
+_wsl() {
+  local tasks='--help          (Display usage information)
+--debug-shell         (Open a WSL2 debug shell for diagnostics purposes)
+--event-viewer        (Opens the application view of the Windows Event Viewer)
+--unregister      (deletes the root filesystem)
+--terminate     (Terminates the specified distribution)
+--set-default   (Sets the distribution as the default)
+--shutdown      (Immediately terminates all running distributions)
+--release-notes (Opens a web browser to view the WSL release notes page)
+--manage        (Changes distro specific options)
+--install       (Install a Windows Subsystem for Linux distribution)
+--set-default-version (Changes the default install version for new distributions)
+--status        (Show the status of Windows Subsystem for Linux)
+--update        (Update the Windows Subsystem for Linux package)
+--version       (Display version information)
+--list          (Lists distributions)
+--export        (Exports the distribution to a tar file)
+--import        (Imports the specified tar file as a new distribution)
+--import-in-place (Imports the specified .vhdx file as a new distribution)'
+
+  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
+  return 0
+} &&
+complete -F _wsl wsl