badmotorfinger / z

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

Allow z to work on Linux #45

Closed joejag closed 4 years ago

joejag commented 4 years ago

This PR changes three things about how the current code works to make it work on Linux (#44)

  1. Use $Env.HOME over $Env.USERPROFILE

I understand this works on all platforms, this is the only change which Windows users will see from this PR.

  1. Disable the $providerMatches regex check which was preventing the run on Linux

This was the second cross-platform bug in the current code.

The regex I suspect is doing something Windows-specific. It looks like this: '(?i)^((Alias|Env|/|Function|Variable):\\)|(\\{1,2}).*?'. That seems to fail for all paths stored in $global:history on Linux. I've put the code behind a $IsWindows to keep that behaviour there, as I couldn't think of the real use cases where the regex is useful.

  1. Allow $function:tabexpansion2 to work on non-Windows platforms

We were using a -Replace to extend the existing $function:tabexpansion2 which uses Windows-style newlines of \r\n which wasn't matching on Linux and clearing out the whole of the $function:tabexpansion2 variable. I've changed the -Replace matcher to work for \n which is the default newline on Linux and Mac.

Minor things:

joejag commented 4 years ago

Going to rework this and resubmit