The untouchable Powsershell
Recently I got a new Windows PC at home (for learning), but used to the extreme experience of iTerm2 + Oh My Zsh on MAC, this default Powsershell really put me off!
As the saying goes: If you have a problem, Google it! . I’ve found a really nice tool for posh-git
GitHub:posh-git
In fact, there are a lot of tools to achieve, but here I think the whole better to use, configuration is relatively simple. Don’t fight me, fight that’s: Ah yeah yeah yeah
Let’s see the effect first
Is not afraid of beautiful many haha, suddenly the whole person are comfortable, next will tell how to use it!
Two, beautifulposh-git
First open the Posh – Git github repository, REMADE has it all covered, so here’s a summary
1. Preparation for use
There are three requirements before installation
-
Your local Windows PowserShell must be 5.X or PowerShell Core 6.0, which can be checked with $psversionTable.psversion
If you find that you don’t meet the criteria, you can get PowerShell Core 6.0 for Windows, Linux, or macOS here
-
On Windows, the script execution policy must be set to RemoteSigned or Unrestricted
To check your own script ExecutionPolicy Settings, run the get-executionpolicy from PowserShell. If the policy is not RemoteSigned or Unrestricted, Run PowerShell as an administrator and run set-executionPolicy Remotesune-scope currentUser-confirm
-
Git must be installed and the environment variables have been successfully configured
2. Download and install
There are many installation methods introduced by the official. Here is how to install the built-in PowerShellGet module
Open Windows PowerShell 5.x or PowerShell >= v6
If you have posh-git installed before, run PowerShellGet\ update-module posh-git
If you have never installed posh-git, run PowerShellGet\ install-module posh- git-scope currentUser-force
Run import-module posh-git this will add commands to your PowerShell configuration file script
Re-open PowerShell at this point and you will see that you have made basic changes
3. Make PowserShell a more extreme experience
Start by finding out where our PowserShell configuration file is
In PowerShell$profile
You can see the location of our PowserShell configuration file
This is shown as microsoft.powershell_profile.ps1 and some versions are shown as profile.ps1
Then we open the configuration file and find that the import-module posh-git command has been configured in it
-
Disable git status information
The default
posh-git
The git status change will be displayed, but this seems to be very inconsistent with the requirements of the extreme experience, so we turn it off.Add the following code to our PowerShell configuration file, save it and re-open PowserShell and it should be pretty neat
$GitPromptSettings.EnableFileStatus = $false Copy the code
-
Display color timestamp
Add the following code to our PowerShell configuration file, save it and reopen PowserShell
$GitPromptSettings.DefaultPromptPrefix.Text = '$(Get-Date -f "MM-dd HH:mm:ss") '/ / the timestamp format here. Can also be custom modified $GitPromptSettings DefaultPromptPrefix. ForegroundColor = [ConsoleColor] : : Magenta / / the color can custom modification hereCopy the code
To see the results
-
Replace the file path in the home directory with ~
Add the following code to our PowerShell configuration file, save it and reopen PowserShell
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true Copy the code
-
Change the color of the directory path
Add the following code to our PowerShell configuration file, save it and reopen PowserShell
$GitPromptSettings.DefaultPromptPath.ForegroundColor = 'Orange'// The color can be customizedCopy the code
The above is a very useful feeling, it is recommended to configure. Below is a list of configurations that feel almost useless, but in case everyone likes them, so include them
-
Add a line break after the display
Add the following code to our PowerShell configuration file, save it and reopen PowserShell
$GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n' Copy the code
-
Swap the location of paths and branch names
Add the following code to our PowerShell configuration file, save it and reopen PowserShell
$GitPromptSettings.DefaultPromptWriteStatusFirst = $true Copy the code
And that’s basically it
Attach the complete configuration code
Import-Module posh-git
$GitPromptSettings.EnableFileStatus = $false
$GitPromptSettings.DefaultPromptPrefix.Text = '$(Get-Date -f "MM-dd HH:mm:ss") '
$GitPromptSettings.DefaultPromptPrefix.ForegroundColor = [ConsoleColor]::Magenta
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true
$GitPromptSettings.DefaultPromptPath.ForegroundColor = 'Orange'
$GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n'
$GitPromptSettings.DefaultPromptWriteStatusFirst = $true
Copy the code