添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Integrate Linux Commands into Windows with PowerShell and the Windows Subsystem for Linux

Mike Battista

Sharing SSH keys between Windows and WSL 2
I recently wrote an article for Smashing Magazine that covers how I set up my personal development environment to use the Windows Subsystem for Linux version 2 (WSL 2). ...
Burke Holland
16 comments

Or at least go the other way and run whatever occasional Windows commands you need from bash under wsl, since the UNIX “execl” lets bash securely and correctly expand arbitrary file names and pass them to commands without using musical quotes (I notice the script concatenates file names separated by spaces, yuck!).

The best thing that Windows could do is adopt the UNIX fork/exec/wait argument passing and process hierarchy, and use the “jam everything into a quoted string and hope for the best” for legacy commands only.

As long as you install the azure-cli tools inside WSL, and it registers a bash completion spec (looks like it does), you can just add Import-WslCommand “az” to your PowerShell profile and it will allow you to call az from PowerShell with argument completion. Just tried it myself and it works great as long as you’re ok with az running within WSL. Make sure you take the latest code from the GitHub repo since it will automatically detect the bash completion function to use once you install the tools within WSL.

Some resources:
https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest#install-with-one-command
https://github.com/Azure/azure-cli/blob/dev/az.completion

Follow-up: is there a way to tweak the colors scheme used for the colorized output? I tried with:

$WslEnvironmentVariables["LS_COLORS"] = "colors here..."

But no luck =(

Yes. From my quick tests, when setting LS_COLORS you need to ensure you set the colors on the right file types for Windows files which isn’t exactly obvious.

For example, changing di colors will not have any effect on Windows directories, but changing ow colors will.

The best guide I could find on LS_COLORS was https://askubuntu.com/questions/466198/how-do-i-change-the-color-for-directories-with-ls-in-the-console .

Once you know the foreground/background codes, you can narrow down which file type to modify based on the default colors you see as defined by dircolors and then change the respective file type to whatever colors you want.

Powershell functions are not only options anymore. wsl-call allows to create symlinks to each linux in wsl command and if placed in PATH run as usual linux cli without wsl.exe upfront.
https://github.com/sashafirsov/wsl-call

Topics