问题描述
我有启用了 WSL 的 Windows 10 操作系统并安装了适用于 Windows 的 docker。
当我在 PowerShell 中输入 docker 并点击 tab 时,它会建议我在我的工作目录中使用相应的文件夹和文件。
这里的 AndroidStudioProjects 是我工作目录中的一个目录。
另一方面, 当我在 WSL Ubuntu 中输入 docker 并点击 tab 时,它会建议可用的 docker 命令本身。 (我的预期行为)
我希望 PowerShell 也像 WSL ubuntu 一样推荐。
解决方法
大概:
-
WSL 上的
-
docker
带有 POSIX 兼容 shell 的制表符补全功能,例如通过 shell 的初始化文件安装的bash
。 -
没有为 PowerShell 提供此类支持,但有第三方解决方案 - 见下文。
为 docker
安装 PowerShell 制表符补全:
从 PowerShell 库安装 DockerCompletion
module:
# 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 选项卡补全:
posh-cli
meta-module - 其存储库为 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。