Posh-git: PowerShell Core on Linux support

Created on 21 Aug 2016  路  14Comments  路  Source: dahlbyk/posh-git

Issues I've found running posh-git on OS X:

  • [ ] Path separators are a known issue in PowerShell on Linux: only forward slashes are supported (https://github.com/PowerShell/PowerShell/blob/master/docs/KNOWNISSUES.md#directly). profile.example.ps1 uses .\posh-git rather than Join-Path . posh-git. Failing that, swapping to forward slash would work as they are supported everywhere.
  • [x] Administrator check in GitPrompt.ps1:98 doesn't work as [Security.Principal.WindowsIdentity]::GetCurrent() is unsupported.
  • [x] GitUtils.ps1:226 doesn't work for setting env variables, as [EnvironmentVariableTarget] is unavailable. We use Process, which is the default, so could skip this.
  • [x] The prompt shows up twice. This isn't actually our fault, there's an issue with using Write-Host in the prompt on OS X/Linux. Tracked upstream at https://github.com/PowerShell/PowerShell/issues/1897
  • [ ] Actual ssh-agent support could probably be better. ssh-agent always runs OS X 10.5+ and uses Keychain as storage so I'm not sure how much posh-git actually needs to manage agent/keys on OS X.
Area-SSH Cross-Platform Discussion Enhancement

Most helpful comment

Thanks, @andschwa!

Double prompting is a strange bug; I believe @ealexjordan is working on it.

Don't spend too much time there, at least for our benefit: as of #304 we won't need to Write-Host in prompt.

All 14 comments

Can confirm similar issues exist on Ubuntu 14.04.

Path separators actually shouldn't be an issue. PowerShell on Linux translates backslashes to forward slashes to be "slash agnostic"; what this prevents is a backslash as a literal character in a path name due to the inability to escape it. But your use of \ as a / should be just fine.

Anything using Security.Principal.WindowsIdentity is just (expectedly) not going to work on Linux.

You honestly may just want to wait for EnvironmentVariableTarget. It's been added back to CoreFX. However, if you note the date, that was July 5th, and the stable release that PowerShell is using was published June 27th. So when .NET Core drops their next big release and PowerShell picks it up, this problem just goes away. (And then GetCurrent can turn into [Environment]::UserName probably.)

Double prompting is a strange bug; I believe @ealexjordan is working on it.

Thanks, @andschwa!

Double prompting is a strange bug; I believe @ealexjordan is working on it.

Don't spend too much time there, at least for our benefit: as of #304 we won't need to Write-Host in prompt.

Issues 2 and 3 have been addressed. Issue 1 "shouldn't" be an issue for PowerShell commands but anytime a path is passed to an external application, the path sep char probably needs to be correct for the platform. Regarding issue 4, that is a known PSReadLine issue. Issue 5 needs further investigation.

And as @dahlbyk mentions, there is an issue with the use of Write-Host in Write-Prompt. On Window 10 AU and Linux/macOS, folks are going to want to start using ANSI esc sequences to colorize their prompt text. There should be a way to allow that while still maintaining the old way for back compat (or for hosts that don't support ANSI escape seqs).

Issues 2 and 3 have been addressed.

By #312 and #318, respectively.

Are there any specific spots that Issue 1 (path separators) were an issue? https://github.com/dahlbyk/posh-git/pull/325 did make a minor change along these lines.

Issue 4 should be resolved by #304.

Issue 5 is related to https://github.com/dahlbyk/posh-git/pull/295. Are there any environment variables set by ssh-agent on macOS (e.g. SSH_AGENT_PID)?

Finally got around to testing this out myself (on develop branch). Only error so far seems to be unreported (Add-Member).

bash_2017-03-05_00-08-03

image

You can fix this with -Force - in GitUtils.ps1 starting at line 298:

            Add-Member -PassThru -Force NoteProperty Added    $indexAdded.ToArray() |
            Add-Member -PassThru -Force NoteProperty Modified $indexModified.ToArray() |
            Add-Member -PassThru -Force NoteProperty Deleted  $indexDeleted.ToArray() |
            Add-Member -PassThru -Force NoteProperty Unmerged $indexUnmerged.ToArray()

        $working = (,$workingPaths) |
            Add-Member -PassThru -Force NoteProperty Added    $filesAdded |
            Add-Member -PassThru -Force NoteProperty Modified $filesModified.ToArray() |
            Add-Member -PassThru -Force NoteProperty Deleted  $filesDeleted.ToArray() |
            Add-Member -PassThru -Force NoteProperty Unmerged $filesUnmerged.ToArray()

Fixed the Add-Member errors via PR #514

@rkeithhill is Pester able to run on PS Core on Travis? Would be great to have non-Windows CI to have some confidence that we're not completely broken.

Path separators are a known issue in PowerShell on Linux

This doesn't seem to be completely resolved yet.

Actual ssh-agent support could probably be better.

Let's assume this will be resolved by #338.

Pester is running cross-plat on PS Core. Would be good to test on Linux/macOS.

I've enabled Travis CI for this repo, if anyone cares to add a .travis.yml and get the build working.

https://github.com/pester/Pester/blob/0f5aff9fc34323659f9d68c29b3265a7f0d6bf6a/.travis.yml

Other than deciding what to do about ssh-agent, are there any lingering issues with posh-git on Linux as of beta2?

None that I can think of that are in our control. The only issue I see is that we are dependent on a beta of PSReadLine to be really usable on Linux. I'm hoping PS Core 6.1 will ship with PSReadLine 2.0.0.

I believe with the removal of SSH functionality to the posh-sshell module there is nothing left to do for this issue. I have been using posh-git on Ubuntu 18.04 for months now without issues.

Was this page helpful?
0 / 5 - 0 ratings