像 Linux-bash 一样推荐 PowerShell(例如 docker)

Yog*_*esh 4 powershell autocomplete tab-completion docker windows-subsystem-for-linux

我有 Windows 10 操作系统,启用了 WSL,并安装了 docker for windows。

当我在 PowerShell 中输入 docker 并点击 Tab 时,它会建议我使用工作目录中相应的文件夹和文件。

这里AndroidStudioProjects是我工作目录中的一个目录。 在此输入图像描述

另一方面,当我在 WSL Ubuntu 中输入 docker 并点击选项卡时,它会建议可用的 docker 命令本身。(我的预期行为) 在此输入图像描述

我希望 PowerShell 也像 WSL ubuntu 一样推荐。

mkl*_*nt0 9

想必:

  • dockerWSL 为POSIX 兼容 shell提供了制表符补全功能,例如bash,通过 shell 的初始化文件安装。

  • PowerShell不提供此类支持,但有第三方解决方案 - 见下文。


安装 PowerShell 制表符补全docker

从 PowerShell 库安装DockerCompletion模块:

# 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 
Run Code Online (Sandbox Code Playgroud)

为所有受支持的程序 (CLI)安装 PowerShell Tab 自动补全:

posh-cli模块(其存储库位于此处)提供了一种便捷的方法,可以为所有本地安装的 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
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅自述文件。