Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell 6.0 - Linux #35

Closed
patrolez opened this issue Oct 24, 2017 · 2 comments
Closed

PowerShell 6.0 - Linux #35

patrolez opened this issue Oct 24, 2017 · 2 comments

Comments

@patrolez
Copy link

Hi,
I am trying PowerShell in Linux and maybe as you know PowerShell 6.0 is developed to be able to work with .NET Core "stack".

I have made some changes to get z working with Linux as there are some platform related differences, but that changes are made in "hacking" manner. It would break Windows platform.

I have seen that some of regular expressions are build during runtime based on "Get-PSProvider" output.

In Linux the output looks like:

Get-PSProvider

Name          Capabilities                          Drives     
----          ------------                          ------     
Alias         ShouldProcess                         {Alias}    
Environment   ShouldProcess                         {Env}      
FileSystem    Filter, ShouldProcess, Credentials    {/}        
Function      ShouldProcess                         {Function} 
Variable      ShouldProcess                         {Variable}

Diff is pretty simple. In Linux there is different convention in FileSystem tree traversal.
Things are not accessed via <DRIVE/RESOURCE>:\.

diff --git a/z.psm1 b/z.psm1
index 7e75039..826d0f4 100644
--- a/z.psm1
+++ b/z.psm1
@@ -368,7 +368,7 @@ function Get-CurrentSessionProviderDrives([System.Collections.ArrayList] $Provid
         # An ideal solution would be to ask the provider if a path is supported.
         # Supports drives such as C:\ and also UNC \\
         if ((Get-Location).Provider.ImplementingType.Name -eq 'FileSystemProvider') {
-            '(?i)^(((' + [String]::Concat( ((Get-Location).Provider.Drives.Name | % { $_ + '|' }) ).TrimEnd('|') + '):\\)|(\\{1,2})).*?'
+            '(?i)^(((' + [String]::Concat( ((Get-Location).Provider.Drives.Name | % { $_ + '|' }) ).TrimEnd('|') + '))|(\\{1,2})).*?'
         } else {
             Get-ProviderDrivesRegex (Get-Location).Provider.Drives
         }
@@ -386,7 +386,7 @@ function Get-ProviderDrivesRegex([System.Collections.ArrayList] $ProviderDrives)
         '(?i)^(\\{1,2}).*?'
     } else {
         $uncRootPathRegex = '|(\\{1,2})'
-        '(?i)^((' + [String]::Concat( ($ProviderDrives | % { $_ + '|' }) ).TrimEnd('|') + '):\\)' + $uncRootPathRegex + '.*?'
+        '(?i)^((' + [String]::Concat( ($ProviderDrives | % { $_ + '|' }) ).TrimEnd('|') + '))' + $uncRootPathRegex + '.*?'
     }
 }

For now I have no knowledge to provide some changes to not break Windows platform, so this is in some way Feature Request :D

@badmotorfinger
Copy link
Owner

Thank you for taking the time to submit this request.

Although I use Linux from time to time, it's not enough to justify the hours it would take to get it working and tested. If I had unit tests written in Pester I think I'd probably have the confidence to do this :-)

If you would like to do the changes to make it compatible I'd be more than happy to have the branch installed on my Windows machine for testing purposes. If the branch proves stable after some use, then I'm happy for it to go into master.

@badmotorfinger
Copy link
Owner

I totally forgot to mention that this PowerShell script is a port of a bash script. See https://github.com/rupa/z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants