badmotorfinger / z

Save time typing out directory paths in PowerShell by jumping around instead.
The Unlicense
434 stars 33 forks source link

PowerShell 6.0 - Linux #35

Closed patrolez closed 6 years ago

patrolez commented 7 years ago

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 commented 7 years ago

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 commented 6 years ago

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