我的 Windows 10 操作系统启用了 WSL 并安装了适用于 Windows 的 docker。
当我在 PowerShell 中键入 docker 并点击 Tab 键时,它会建议我在工作目录中找到相应的文件夹和文件。
此处 AndroidStudioProjects 是我工作目录中的一个目录。
另一方面, 当我在 WSL Ubuntu 中键入 docker 并点击选项卡时,它会建议可用的 docker 命令本身。 (我的预期行为)
我希望PowerShell也像WSL ubuntu一样推荐。
最佳答案
据推测:
-
WSL 上的
docker
带有用于 POSIX 兼容 shell 的制表符完成功能,例如bash
,通过 shell 的初始化文件安装.没有为 PowerShell 提供此类支持,但有第三方解决方案 - 见下文。
为 docker
安装 PowerShell tab-completion:
安装 DockerCompletion
module来自 PowerShell 库:
# Install the module in the scope of the current user.
Install-Module DockerCompletion -Scope CurrentUser
# Import the module into the session.
# Add this line to your $PROFILE file to make the tab-completion
# available in future sessions.
Import-Module DockerCompletion
为所有支持的程序(CLI)安装 PowerShell tab 完成:
posh-cli
meta-module - 其 repo 是 here - 提供了一种方便的方法为所有本地安装的 CLI 自动安装制表符完成支持,这些 CLI 可以使用特定于应用程序的制表符完成模块:
# Install the meta-module in the scope of the current user.
Install-Module posh-cli -Scope CurrentUser
# This looks for locally installed CLIs for which tab-completion
# modules are available, installs them, and adds
# Import-Module commands to your $PROFILE file.
Install-TabCompletion
参见 the README获取更多信息。
关于docker - 使 PowerShell 推荐像 Linux-bash(例如 docker),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66479577/