mikebattista / powershell-wsl-interop Goto Github PK
View Code? Open in Web Editor NEWIntegrate Linux commands into Windows with PowerShell and the Windows Subsystem for Linux (WSL).
License: MIT License
Integrate Linux commands into Windows with PowerShell and the Windows Subsystem for Linux (WSL).
License: MIT License
Test-Path is used but that only returns true for paths that exist which is helpful to differentiate Linux paths from Windows paths but falls flat if a wildcard pattern is provided that doesn't return any results or if the user is passing a path for a to-be-created file.
I tried using loading the WslInterop module in my profile.
But then it makes loading the profile very slow...
Implementing the function wrapper directly like explained in the article seems way more efficient.
Or am I doing something wrong?
ls /mnt/c/Program\ Files/<TAB> returns no results.
Bash continues to complete these paths.
Describe the bug
\wsl$<distro_name><path> UNC path syntax is not converted to linux path
e.g. \wsl$\Ubuntu\etc\wsl.conf to /etc/wsl.conf
To Reproduce
Steps to reproduce the behavior:
pwsh
vim '\\wsl$\Ubuntu\etc\wsl.conf'
Expected behavior
Path conversion working.
e.g. convert \wsl$\Ubuntu\etc\wsl.conf to /etc/wsl.conf
Desktop (please complete the following information):
Additional context
Good thing to note is that this still won't work across multiple wsl distros.
vim '\\wsl$\Ubuntu\etc\wsl.conf'
vim '\\wsl$\Debian\etc\wsl.conf'
Not sure if this issue can be solved, anyway - thanks a ton for your great work on this 😄
Describe the bug
There are various bugs with the "-exec" parameter of the find command. Arguments to -exec
do not work and result in errors.
To Reproduce
find . -exec echo blub \;
find . -exec echo {} \;
Expected behavior
The first command should output "blub" for every item found.
The second command should output the pathname of every item found.
Screenshots
Output of first command:
find: missing argument to `-exec'
Output of second command:
Test-Path:
Line |
22 | } elseif (Test-Path $args[$i] -ErrorAction Ignore) {
| ~~~~~~~~~
| Cannot evaluate parameter 'Path' because its argument is specified as a script block and there is no input. A script block cannot be evaluated without input.
find: missing argument to `-exec'
Desktop (please complete the following information):
For a directory containing Documents and Downloads:
All of these patterns work when passed to wsl ls directly, so wslpath is definitely the culprit here.
When installing the module using
Install-Module WslInterop
adding
Import-WslCommand "awk", "emacs", "grep", "head", "less", "ls", "man", "sed", "seq", "ssh", "tail", "vim", "bash"
$WslDefaultParameterValues["grep"] = "-E"
$WslDefaultParameterValues["less"] = "-i"
$WslDefaultParameterValues["ls"] = "-AFh --group-directories-first"
$WslDefaultParameterValues["bash"] = "--login --init-file ~/.nix-profile/etc/profile.d/nix.sh"
and the reloading profile I get a bunch of:
Cannot index into a null array.
At ...\Documents\PowerShell\Microsoft.PowerShell_profile.ps1:8 char:1
- $WslDefaultParameterValues["grep"] = "-E"
- CategoryInfo : InvalidOperation: (:) [], RuntimeException
- FullyQualifiedErrorId : NullArray
I have an alias ll
for instance that is defined as alias ll="ls -lhA --color=auto"
in .bash_aliases
. How can I export this alias so that I can use it in PowerShell?
Thanks.
Invoke-WslCommand would use $MyInvocation.InvocationName to know which alias was used to call it and then pass that down to wsl.
This works great except in cases where the alias is invoked using the call operator (&). The canonical sample is setting $Env:PAGER = "less" and then calling help which uses the & operator to invoke the pager.
In this scenario, I don't see a way yet to retrieve the alias that was used to call Invoke-WslCommand since $MyInvocation.InvocationName is just '&' in this case.
Describe the bug
Executing a command that was imported using Import-WslCommand no longer executes with the following error in Powershell 7.3.0:
/bin/bash: : command not found
To Reproduce
Steps to reproduce the behavior:
Import-WslCommand ls
ls
Expected behavior
Execution of the command should work and error should not be displayed.
Desktop (please complete the following information):
Additional context
This works fine in Powershell 7.2.3 but confirmed broken after upgrade to 7.3.0
/usr/share/bash-completion/bash_completion has many _install_xspec calls for lots of commands for which completion specs are later defined in a call to __load_completion defined in the same file.
See if explicitly calling __load_completion helps identify the right completion spec.
Describe the bug
Awk is not working correctly when running in Powershell. It works in my WSL2 instance but not while using Interoped commands via the WslInterop module.
To Reproduce
So I created a test.txt file that I can use to get familiar with awk and then tried a simple command.
PS C:\Users\interopUser> touch test.txt
PS C:\Users\interopUser> echo "Name, Age, City" > test.txt
PS C:\Users\interopUser> echo "Alice, 25, New York" >> test.txt
PS C:\Users\interopUser> echo "Bob, 30, Los Angeles" >> test.txt
PS C:\Users\interopUser> echo "Charlie, 22, Chicago" >> test.txt
PS C:\Users\interopUser> echo "David, 35, Houston" >> test.txt
PS C:\Users\interopUser> echo "Eva, 28, Miami" >> test.txt
PS C:\Users\interopUser> cat .\test.txt
Name, Age, City
Alice, 25, New York
Bob, 30, Los Angeles
Charlie, 22, Chicago
David, 35, Houston
Eva, 28, Miami
PS C:\Users\interopUser> awk -F', ' '{print $2}' test.txt
Name, Age, City
Alice, 25, New York
Bob, 30, Los Angeles
Charlie, 22, Chicago
David, 35, Houston
Eva, 28, Miami
As you can see the awk command did not work correctly.
So then I tried to do the same in wsl2 see here:
interopUser@UAS2324401:~$ touch test.txt
interopUser@UAS2324401:~$ echo "Name, Age, City" > test.txt
echo "Alice, 25, New York" >> test.txt
echo "Bob, 30, Los Angeles" >> test.txt
echo "Charlie, 22, Chicago" >> test.txt
echo "David, 35, Houston" >> test.txt
echo "Eva, 28, Miami" >> test.txt
interopUser@UAS2324401:~$ cat test.txt
Name, Age, City
Alice, 25, New York
Bob, 30, Los Angeles
Charlie, 22, Chicago
David, 35, Houston
Eva, 28, Miami
interopUser@UAS2324401:~$ awk -F', ' '{print $2}' test.txt
Age
25
30
22
35
28
And as expected the awk command worked in WSL2
Expected behavior
The expected behavior is to have the awk command work in the same manner in Powershell as it does for WSL2
Desktop (please complete the following information):
Additional context
Here is what is being placed in my profile to help make this work:
Import-WslCommand "grep", "tail", "touch", "man", "awk", "cut", "vim"
Describe the bug
PowerShell passes down command to be completed with trimmed spaces and some completions don't work because of that.
To Reproduce
Steps to reproduce the behavior:
pwsh
code --disable-extension <tab>
--disable-extension --disable-extensions
Expected behavior
PowerShell outputting completions for command that has spaces at the end.
code --disable-extension <tab>
adamsome.vscode-theme-gruvbox-minor ms-azuretools.vscode-docker
akamud.vscode-theme-onedark ms-dotnettools.csharp
apollographql.vscode-apollo ms-edgedevtools.vscode-edge-devtools
Desktop (please complete the following information):
Additional context
The solution I found that works is to pad the $COMP_LINE
until your cursor position $cursorPosition
.
So instead of this:
$COMP_LINE = "`"$commandAst`""
do this:
$compLine = "$commandAst".PadRight($cursorPosition)
$COMP_LINE = "`"$compLine`""
"/mnt/c/program\ files" ends up getting split into 2 separate (invalid paths) since it splits on spaces.
I followed the instructions on the README, installed PS Core, the package with the package manager, I can add new aliases (with Import-WslCommand) of my WSL, and it works. But when I close the PowerShell window, and open a new one, the aliases are gone.
Describe the bug
Cannot run npm
.
To Reproduce
In Ubuntu-20.04 run:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm install --lts
nvm use --lts
npm --version
- should return version
Run PowerShell Script:
Import-Module "WslInterop"
Import-WslCommand "nvm", "npm", "ls"
nvm --version
npm --version
ls -la
Expected behavior
I've thought this PowerShell module solves https://stackoverflow.com/questions/61823716/wsl-on-windows-10-not-loading-config-files-when-ran-interoperabiltiy
Hi,
after following readme and storing 'PowerShell WSL Interop.ps1' as 'Profile.ps1', I get this error on powershell startup:
PowerShell 6.2.3
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
At C:\Program Files\PowerShell\6\profile.ps1:169 char:190
+ ... ata-ga-click="(Logged out) Header, go to Features">Features <span cla ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:185 char:255
+ ... ogged out) Header, go to Customer stories">Customer stories <span cla ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:186 char:231
+ ... ata-ga-click="(Logged out) Header, go to Security">Security <span cla ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:206 char:222
+ ... a-click="(Logged out) Header, go to Explore">Explore GitHub <span cla ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:242 char:185
+ ... r" data-ga-click="(Logged out) Header, go to Pricing">Plans <span cla ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:250 char:235
+ ... -ga-click="(Logged out) Header, go to Nonprofits">Nonprofit <span cla ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:251 char:258
+ ... a-ga-click="(Logged out) Header, go to Education">Education <span cla ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:822 char:93
+ ... b-code blob-code-inner js-file-line"><span class="pl-c"> </span></ ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:830 char:93
+ ... b-code blob-code-inner js-file-line"><span class="pl-c"> </span></ ...
+ ~
The '<' operator is reserved for future use.
At C:\Program Files\PowerShell\6\profile.ps1:874 char:122
+ ... le-line"><span class="pl-c"> * $WslDefaultParameterValues["gr ...
+ ~
Array index expression is missing or not valid.
Not all parse errors were reported. Correct the reported errors and try again.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : RedirectionNotSupported
Any advice, please?
Use -LiteralPath when an invalid wildcard pattern is detected.
Describe the bug
Hi. Thanks a lot for this project. It used to work very well, but recently I tried again and apparently all commands are failing with zsh:1: permission denied:
.
To Reproduce
I can reproduce it locally, feel free to ask me any details.
Expected behavior
To work, I guess.
Desktop (please complete the following information):
Additional context
Any help is really appreciated. Thanks!
@mikebattista raised this issue offline today. It's an edge case, but strikes when $env:PAGER
is set to less
in PowerShell.
$mysteriousCommand = 'grep'
& $mysteriousCommand .log
Runs grep
via WSL.
Is unable to resolve the alias, since $MyInvocation.InvocationName
is unhelpfully &
...
Ideally, PowerShell should create more information here, but to work around this, the most straightforward solution might be to create functions rather than aliases, which wrap Invoke-WslCommand
:
function grep
{
Invoke-WslCommand -CommandName grep ...
}
Hi,
I get an error when using $WslDefaultParameterValues on Powershell 7.0.0 and WslInterop 0.2.2
$WslDefaultParameterValues["ls"] = "-AFh --group-directories-first" InvalidOperation: Cannot index into a null array.
The commands themselves work, but also the resolving of Linux paths does not work. I tested on Windows 10 1809 and 1909.
Best regards
Describe the bug
Executing an imported command fails with path translation failures and mount failure. See "screenshots" below.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Powershell executes the fmt program from WSL.
Screenshots
C:\Users\user> import-wslcommand "fmt", "indent"
C:\Users\user> fmt
<3>WSL (9) ERROR: CreateProcessParseCommon:711: Failed to translate C:\Users\user
<3>WSL (9) ERROR: CreateProcessParseCommon:757: getpwuid(0) failed 2
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\PowerShell\7
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\OpenSSH\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files (x86)\Razer Chroma SDK\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Razer Chroma SDK\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files (x86)\Razer\ChromaBroadcast\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Razer\ChromaBroadcast\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Microsoft\jdk-11.0.19.7-hotspot\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\system32
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\System32\Wbem
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\System32\WindowsPowerShell\v1.0\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\System32\OpenSSH\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\MATLAB\R2022b\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Microsoft SQL Server\150\Tools\Binn\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Git LFS
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\dotnet\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\AppData\Local\Microsoft\WindowsApps
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\AppData\Local\Programs\Microsoft VS Code\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\.dotnet\tools
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Vim\vim90\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\AppData\Local\Microsoft\WinGet\Links
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Windows Kits\10\Testing\Runtimes\TAEF\x64
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Windows Kits\10\Testing\Runtimes\TAEF\x86
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\PowerShell\7\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Docker\Docker\resources\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files (x86)\GnuPG\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Go\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\GitHub CLI\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Git\cmd
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Amazon\AWSCLIV2\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\AppData\Local\Microsoft\WindowsApps
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\AppData\Local\Programs\Microsoft VS Code\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\.dotnet\tools
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Vim\vim91\
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\AppData\Local\Microsoft\WinGet\Links
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\texlive\2023\bin\windows
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\GNU Octave\Octave-8.4.0\mingw64\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Windows Kits\10\Testing\Runtimes\TAEF\x64
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Windows Kits\10\Testing\Runtimes\TAEF\x86
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Users\user\go\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\GitHub CLI
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Graphviz\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\doxygen\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin
<3>WSL (9) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\7-Zip
Processing fstab with mount -a failed.
Failed to mount C:\, see dmesg for more details.
<3>WSL (9) ERROR: CreateProcessEntryCommon:334: getpwuid(0) failed 2
<3>WSL (9) ERROR: CreateProcessEntryCommon:505: execvpe /bin/sh failed 2
<3>WSL (9) ERROR: CreateProcessEntryCommon:508: Create process not expected to return
C:\Users\user>
Desktop (please complete the following information):
C:\Users\user> $PSEdition
Core
C:\Users\user> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
If I can remove the need for the user to modify the code (e.g. to update the $F argument completion map), then publish as a script module on PSGallery.
Hi, I recently learned about this project and it is a game changer. Thanks for this.
However, since it is painful (at least for me) to write aliases for Powershell, I was wondering if it is possible to import bash aliases to PowerShell. This will help a lot.
Thanks a lot.
shopt -s nocaseglob changes bash to be case insensitive for filename expansion.
Try to set this in the wsl commandLine.
Describe the bug
I have followed the instructions to map various Linux command, including less
. If I try to pipe output via less
, the command hangs at the colon prompt until I hit CTRL-C
. This happens on a distro running as WSL v2. Version 1 distros are fine.
To Reproduce
Steps to reproduce the behavior:
Import-WslCommand "apt", "awk", "grep", "head", "less", "sed", "seq", "tail", "dos2unix", "du", "df", "wget", "gzip", "cat", "free", "top", "uname", "wc"
wsl -s Ubuntu
wsl --set-version Ubuntu 2
cd <a folder with more than a page of files>
ls | less
The command hangs at :
. You can't, for example, press f
or b
.
Expected behavior
Piping output to less
should allow you to page up/down, search, etc.
Screenshots
N/A
Desktop (please complete the following information):
Additional context
Changing the distribution to WSL 1 fixes the issue:
wsl --set-version Ubuntu 1
In a new Terminal session, the following now works as expected:
ls | less
Thank you for providing this incredibly useful module.
On import of a command, consider identifying the appropriate bash completion function automatically without any user intervention.
Describe the bug
The argument completer does not find the correct completion for python based commands.
To Reproduce
Steps to reproduce the behavior:
apt install ansible
apt install python3-argcomplete
Test functionality in wsl, e.g.
ansible-playbook --a
this results in
ansible-playbook --ask
Leave wsl and create the command in PowerShell:
Import-WslCommand ansible-playbook
Expected behavior
Getting the same result in PowerShell, but
ansible-playbook --a
results in
ansible-playbook --a
So nothing happens.
Additional context
The behavior is clear, if I query the following in PowerShell
$global:WslCompletionFunctions
I can see that the value for ansible-playbook is "_minimal".
So basically the problem is in line 126 of WslInterop.psm1:
$global:WslCompletionFunctions[$command] = wsl.exe bash -c ". /usr/share/bash-completion/bash_completion 2> /dev/null; __load_completion $command 2> /dev/null; complete -p $command 2> /dev/null | sed -E 's/^complete.-F ([^ ]+).`$/\1/'"
My bash knowledge is way too low to fix this.
Do you have any idea how to fix this or at least what I can manually set by:
$global:WslCompletionFunctions["ansible-playbook"] = "???"
Thx for your great module, I enjoy it almost every day, but this would improve my work even a little more.
Switch to [System.IO.Path]::IsPathFullyQualified.
For example: ls /mnt/c/Program\ Files\ `(x86`). Without escaping the parenthesis PowerShell tries to run x86 as a command.
You could surround the completions with single quotes to avoid this, but in the case of paths, you'd lose wildcard expansion.
Is your feature request related to a problem? Please describe.
I want to add the following .bashrc
function for use (convert string file sizes to bytes):
toBytes() {
echo $1 | echo $((`sed 's/.*/\L\0/;s/t/Xg/;s/g/Xm/;s/m/Xk/;s/k/X/;s/b//;s/X/ *1024/g'`))
}
Describe the solution you'd like
A way to define bash functions that can be used in my PowerShell profile or anywhere else.
Describe alternatives you've considered
Converting the bash function to a PowerShell function. This can be done, but I'd really like the option to just use the bash function.
Additional context
https://stackoverflow.com/questions/17615881/simplest-method-to-convert-file-size-with-suffix-to-bytes
Add common regular expression escape sequences like \d, \s, \w, etc. to Format-WslArgument.
Also, if the user embeds single quotes in an argument (e.g. '''s/;/\n/g'''), leave it alone, otherwise formatting its content may not result in the expected behavior.
Hi, Not sure if this is the correct place to ask this, my apologies if not. I followed the awesome blog that links to this repo and It has worked for a long time. However on windows 11 I'm noticing that the first time you call ls (for example) it's very slow (3 to 5 seconds to list a couple of files). It seems to speed up after that but then will occasionally become slow again.
I was wondering if it were due to the new vmIdleTimeout setting for wsl2 on windows 11; however I cannot seem to get consistent result to confirm that this is the case (even when setting it to 3600000 (A.K.A 1 hour).
Has anyone else experienced the same issue?
Repro:
less 'C:\Program Files\PowerShell\7-preview\LICENSE.txt'
Expected Behavior:
Works as expected.
Actual Behavior:
'C:/Program Files/PowerShell/7-preview/LICENSE.txt': No such file or directory
The single quotes are considered part of the path.
This is a problem for any paths with spaces since they need to be surrounded with quotes. Windows completion automatically inserts quotes when completing paths with spaces.
Note that running wsl wslpath 'C:\Program Files\PowerShell\7-preview\LICENSE.txt'
at the command line directly works as expected, so the escaped quotes in the function wrapper that solved other issues seem to be causing problems here.
Describe the bug
Backslash in escape chars are converted to forward-slash, which makes regex in sed, grep, etc. not work.
To Reproduce
Steps to reproduce the behavior:
PS > echo "asdf" | sed 's/d/\n/'
asnf
PS > cat Env:\Path | sed 's/;/\n/g'
sed: -e expression #1, char 2: unterminated 's' command
/bin/bash: /n/g: No such file or directory
Expected behavior
PS > echo "asdf" | sed 's/d/\n/'
as
f
PS > cat Env:\Path | sed 's/;/\n/g'
C:\Windows\system32
C:\Windows
...
Desktop (please complete the following information):
The path becomes interpreted as a literal path rather than a path with wildcards.
For paths with spaces, the proper way to support wildcards is to omit quotes and escape spaces with a \.
$COMP_POINT
needs to subtract $commandAst.Extent.StartOffset
from the $cursorPosition
to be relative to the command being completed.
Is your feature request related to a problem? Please describe.
Currently we can set the default parameter values in a hashtable named WslDefaultParameterValues.
This is basically a Dictionary<string, string>.
Describe the solution you'd like
I would like to see a modification, e.g. $WslDefaultParameters.
This should check the type. If it is a string, then work like before.
If it is a scriptblock, then get the value at runtime by executiong the function.
Additional context
In case you are asking why I want this:
I am using a commandline tool accepting passwords and want to use PowerShell´s secret store for that.
To combine these, I can to the following:
ansible-playbook playbook.yaml -i /hosts --extra-vars "ansible_become_pass=$((Get-Secret MySecret).Password | ConvertFrom-SecureString -AsPlainText)"
Of course the last parameter is almost always needed and very clumsy to write in this notation.
So what I want to do, is store this expression as a default parameter.
But this does not work as when I put it this way in the dictionary, the $(xxx) part is not evaluated.
I can do the following:
This works of course, but now
$WslDefaultParameterValues[ "ansible-playbook"]
shows my password.
To make the usage conveniant, I would suggest accepting strings and functions. So the typical case works like before, but there is an additional option to make the default parameter generation dynamic.
If I'm not mistaken, the readme claims that by importing a wsl command both command and argument completion is enabled automatically for pwsh as well:
To Reproduce
Steps to reproduce the behavior:
pwsh
:PowerShell 7.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/powershell
Type 'help' to get help.
PS C:\Users\x> pwsh --version
PowerShell 7.0.0
wsl
that has completion enabled in wsl bash
:[x@DESKTOP-04NUF17 ~]$ echo $0
bash
[x@DESKTOP-04NUF17 ~]$ git <tab><tab>
add blame cherry-pick config format-patch gui log.cmd pull remote restore show status worktree
am branch citool describe fsck help merge push repack revert show-branch submodule
apply bundle clean diff gc init mergetool range-diff replace rm sparse-checkout switch
archive checkout clone difftool gitk instaweb mv rebase request-pull send-email stage tag
bisect cherry commit fetch grep log notes reflog reset shortlog stash whatchanged
[x@DESKTOP-04NUF17 ~]$ grep --<tab><tab>
--after-context= --byte-offset --dereference-recursive --exclude-from= --fixed-strings --invert-match --max-count= --null-data --regexp=
--basic-regexp --color --devices= --extended-regexp --help --label= --no-filename --only-matching --text
--before-context= --colour --directories= --file= --ignore-case --line-buffered --no-ignore-case --perl-regexp --version
--binary --context= --exclude= --files-with-matches --include= --line-number --no-messages --quiet --with-filename
--binary-files= --count --exclude-dir= --files-without-match --initial-tab --line-regexp --null --recursive --word-regexp
[lenni@DESKTOP-04NUF17 ~]$ ls --<tab><tab>
--all --dereference-command-line-symlink-to-dir --hide-control-chars --numeric-uid-gid --tabsize=
--almost-all --directory --human-readable --quote-name --time
--author --dired --hyperlink --quoting-style= --time=
--block-size= --escape --ignore= --recursive --time-style=
--classify --file-type --ignore-backups --reverse --version
--color --format= --indicator-style= --show-control-chars --width=
--color= --full-time --inode --si
--context --group-directories-first --kibibytes --size
--dereference --help --literal --sort
--dereference-command-line --hide= --no-group --sort=
wsl
command(s) into pwsh
:PS C:\Users\x> Import-WslCommand "git", "grep", "ls"
PS C:\Users\x>
PS C:\Users\x> git .\.bash_profile<tab>^C
PS C:\Users\x> grep --<tab><tab>^C
PS C:\Users\x> ls --<tab><tab>^C
PS C:\Users\x>
Expected behavior
Tabbing on those commands in pwsh
would provide me with the same completion commands as in bash
.
Desktop (please complete the following information):
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.