Skip to content

Commit 5d12c30

Browse files
author
Klaus Frank
authored
Update for PowerShell 6
Update for PowerShell 6 (Core) and add cross platform support. Currently the "prompt" function set by Posh-Git in PowerShell Core is a little bugged, but I'm sure they will fix it soonish.
1 parent bfc2653 commit 5d12c30

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

book/A-git-in-other-environments/sections/powershell.asc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
(((powershell)))(((tab completion, powershell)))(((shell prompts, powershell)))
55
(((posh-git)))
6-
The legacy command-line terminal on Windows (`cmd.exe`) isn't really capable of a customized Git experience, but if you're using Powershell, you're in luck.
6+
The legacy command-line terminal on Windows (`cmd.exe`) isn't really capable of a customized Git experience, but if you're using Powershell, you're in luck. This also works if you're running PowerShell on any other platform than Windows like Debian.
77
A package called Posh-Git (https://github.com/dahlbyk/posh-git[]) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
88
It looks like this:
99

1010
.Powershell with Posh-git.
1111
image::images/posh-git.png[Powershell with Posh-git.]
1212

1313
==== Installation
14-
===== Prerequisites
14+
===== Prerequisites (Windows only)
1515
Before you're able to run PowerShell scripts on your machine, you need to set your local ExecutionPolicy to RemoteSigned (Basically anything except Undefined and Restricted). If you choose AllSigned instead of RemoteSigned, also local scripts (your own) need to be digitally signed in order to be executed. With RemoteSigned, only Scripts having the "ZoneIdentifier" set to Internet (were downloaded from the web) need to be signed, others not.
1616
If you're an administrator and want to set it for all Users on that machine, use "-Scope LocalMachine".
1717
If you're a normal user, without administrative rights, you can use "-Scope CurrentUser" to set it only for you.
@@ -28,16 +28,19 @@ If you have at least PowerShell 5 or PowerShell 4 with PackageManagement install
2828
More information about the requirements: (https://docs.microsoft.com/en-us/powershell/gallery/psget/get_psget_module[])
2929
[source,powershell]
3030
-----
31+
> Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
3132
> Update-Module PowerShellGet -Force
3233
> Install-Module Posh-Git -Scope AllUsers
3334
-----
34-
If you want to install Posh-Git only for the currnet user and not globaly, use "-Scope CurrentUser" instead.
35+
If you want to install Posh-Git only for the currnet user and not globaly, use "-Scope CurrentUser" instead.
36+
If the 2nd command fails with the message `Update-Module : Module 'PowerShellGet' was not installed by using Install-Module, so it cannot be updated.` You need to run: `Install-Module PowerShellGet -Force -SkipPublisherCheck` instead. This happens, because the modules that ship with Windows Powershell are signed with a different publishment certificate.
3537

3638
===== Update PowerShell Prompt
3739
To include git information in your prompt, posh-git needs to be imported. To do this automatically, include the import statement into you $profile script. This script is executed everytime you open a new PowerShell prompt.
3840
Keep in mind, that there are multiple $profile scripts. E. g. one for the console and a separate one for the ISE.
3941
[source,powershell]
4042
-----
43+
> New-Item -Name $(Split-Path -Path $profile) -ItemType Directory -Force
4144
> 'Import-Module Posh-Git' | Out-File -Append -Encoding default -FilePath $profile
4245
-----
4346

0 commit comments

Comments
 (0)