Basic wsl Bash completion.
# -*- 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