enpitsulin

enpitsulin

这个人很懒,没有留下什么🤡
twitter
github
bilibili
nintendo switch
mastodon

Configure your shell on Windows.

Terminal, is the most primitive input and output environment for users to interact with the operating system, and is also a necessary tool for some advanced system operations.
I often debug scripts and use git frequently, so today I decided to set up a user-friendly shell as a learning environment.

Now let's start customizing the actually very powerful but a bit ugly powershell that comes with Windows 10.

Changing the Color Scheme of PowerShell#

Microsoft provides a small tool called ColorTool.exe to change the color scheme of PowerShell. We can use it to change the theme color of PowerShell.

We can download this tool from the GitHub page of ColorTool. Of course, if you use Scoop or Chocolatey, you can also install it like this:

Scoop

scoop install colortool

Chocolatey

choco install colortool

Here I highly recommend using Scoop, a high-quality package manager, to install ColorTool.


ColorTool is very easy to use. We can use the following command to view the several built-in themes of the tool:

# Note: -s represents schemes
colortool -s

Several built-in color themes|975x325

The previous .ini and .itermcolors files are theme configuration files, and we can directly set the theme using the following command:

# Temporary view
colortool <theme name>
# Define default value
colortool -d <theme name>

For example, if we want to change the theme color to OneHalfDark.itermcolors, we only need to enter the following command to change and preview the update:

colortool OneHalfDark

Since ColorTool directly supports iTerm theme configuration files, we can find the theme background we want to use on the website iterm2colorschemes, and configure it in PowerShell in the same way: locate the theme file you want to change in PowerShell and use the command colortool <theme name>.itermcolors to configure it. At the same time, if you are not satisfied with the above themes, you can also directly configure your own desired themes on this website: terminal.sexy, and apply them in the same way.

Improving the Font of PowerShell#

For most people, the default font "NSimSun" in PowerShell is really ugly.
Due to Microsoft's restrictions on metadata for console fonts:

These fonts must meet the following conditions in the command session window:
 The font must be a monospaced font.
 The font cannot be an italic font.
 The font cannot have negative space for A or C.
 If it is a TrueType font, it must be FF_MODERN.
 If it is not a TrueType font, it must be OEM_CHARSET.
Additional conditions for Asian fonts:
 If it is not a TrueType font, the font name must be "Terminal".
 If it is an Asian TrueType font, it must also use the character set of an Asian language.

Most people may prefer to use a monospaced font suitable for programming, such as Consolas, as the font for PowerShell. However, here I recommend a font called "Sarasa Gothic / 更纱黑体 / 更紗黑體 / 更紗ゴシック" (Sarasa Gothic), which can be downloaded from the GitHub page of Sarasa Gothic.

After downloading and extracting Sarasa Gothic, restart a PowerShell terminal, right-click on the menu bar, select "Properties-Font", and choose Sarasa Gothic in the font selection. The monospaced font suitable for terminal use is "等距更纱黑体 T SC" or "Sarasa Mono T SC".

Now the font has been changed from the awkward "NSimSun" to "Sarasa Gothic".

Customizing the Prompt Unit in PowerShell#

A basic command unit for PowerShell and other shells is roughly as follows:

  • The front part is the Prompt, which can display useful information such as user, system, development environment, version control, etc.
  • The back part is the specific command, which is where we enter commands when performing operations.

Shell command structure|1114x130

Installing oh-my-posh#

We need to start PowerShell with administrator privileges first to perform the installation operation. (Specifically, right-click on the Start button and select "Windows PowerShell (Administrator)".

Then, run the command to install posh-git, which is a dependency of oh-my-posh.

Install-Module posh-git -Scope CurrentUser

If you haven't installed the NuGet provider before, you will be prompted to install NuGet; if you haven't enabled the execution of arbitrary scripts before, you will also be prompted to execute scripts. If you don't have permission to execute scripts, you may need to execute

Set-ExecutionPolicy Bypass

Next, run the command to install oh-my-posh itself.

Install-Module oh-my-posh  -Scope CurrentUser

By now, oh-my-posh has been installed.


Configuring oh-my-posh#

Next, we need to configure oh-my-posh. First,

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE

Then add the following content to the notepad document that opens:

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Agnoster

If everything goes well, restart your PowerShell and you will find that it looks the same as the illustration at the beginning of this section.


PS: The last line of the configuration file, Set-Theme Agnoster, is used to configure the theme. We can modify the Agnoster in this command, which is the "theme name", in the configuration file to change the theme. You can see more themes in the oh-my-posh documentation#Themes.

Working with PowerShell Using Third-Party Terminals#

Now the one I'm using and the one shown in the screenshots in the article are based on ConEmu+Powershell
To be continued

Third-party Terminals with a More Windows 10-style Look#

Fluent Terminal#

Tried for a while and abandoned, it's really gorgeous.

Hyper#

Not tried

Terminus#

Not tried

ConEmu#

Using WSL + zsh#

I don't really understand this aspect. Leave a place for future trials.

Conclusion#

With this, the customization of the default terminal PowerShell in Windows 10 is complete. Enjoy it now.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.