preface

Used to Mac terminal development, switching to Windows, not a tap on the command line, always feel something missing. The default CMD and PowerShell are ugly, Git Bash is hard to use, Xshell, MobaXterm, and Cmder are hard to get used to. Windows Terminal Preview + PowerShell 7 + WSL Terminal can open multiple tabs and split panes, add CentOS 7 to WSL, and add oh-my-Zsh and Homebrew to make it feel like iTerm2 on the Mac.

Open to

1, install,

Open the WSL

WSL is short for Windows Subsystem for Linux, “Windows Subsystem for Linux”.

How to enable: Right-click the logo in the lower left corner of Windows 10, choose Applications and Features, click programs and Features in the upper right corner, click on the left to enable or disable Windows features, drag the scroll bar to the bottom of the right, select Windows Subsystem for Linux, click OK, and restart after completion.

download

Go to Github to download the installation package. The current version is used as an example:

  • Windows Terminal Preview (➘ 1.2.2022.0)
  • PowerShell (➘ 7.0.3)
  • CentOS on WSL (➘ 7.0.1907.3)

The installation

. Double click on the Microsoft. WindowsTerminalPreview_1. 2.2022.0 _8wekyb3d8bbwe msixbundle install Windows Terminal Preview, if you can’t open, Please open Microsoft Store.

Double-click Powershell-7.0.3-win-x64. msi to install PowerShell 7 as the default sh tool.

Unzip CentOS7, cut the CentOS7 folder to drive C (since mine is an SSD, it will work in another location), and double-click Centos7.exe to register the installation.

2, configuration,

Once installed, Windows Terminal Preview can be found in the Start menu or opened with Win+R running wt.

PowerShell can also be found in the Start menu, or run PWSH to open it.

CentOS7 does not appear in the start menu, but can be opened by running bash.

Configure Windows Terminal

Click the arrow on the right of the TAB to open Windows Terminal, and then click Settings to carry out custom configuration. For detailed tutorials, please check Windows Terminal. Here is a copy of my rough configuration:

{
    "$schema": "https://aka.ms/terminal-profiles-schema"."defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}"."copyOnSelect": true."copyFormatting": true."profiles":
    {
        "defaults": {},
        "list": [{"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}"."name": "PowerShell"."commandline": "powershell.exe"."hidden": false
            },
            {
                "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}"."hidden": false."name": "PowerShell7"."source": "Windows.Terminal.PowershellCore"
            },
            {
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}"."name": "Command prompt"."commandline": "cmd.exe"."hidden": false
            },
            {
                "guid": "{a8202b0e-781a-5dab-98e2-e9d469a63619}"."hidden": false."name": "CentOS7"."source": "Windows.Terminal.Wsl"."fontFace": "Fira Code Retina"."fontSize": 10."startingDirectory": "//wsl$/CentOS7/home/admin"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}"."hidden": true."name": "Azure Cloud Shell"."source": "Windows.Terminal.Azure"}},"schemes": []."theme": "dark"."keybindings": [{"command": {"action": "copy"."singleLine": false }, "keys": "ctrl+c" },
        { "command": "paste"."keys": "ctrl+v" },
        { "command": "find"."keys": "ctrl+shift+f" },
        { "command": { "action": "splitPane"."split": "auto"."splitMode": "duplicate" }, "keys": "alt+shift+d"}]."initialCols": 98."initialRows": 26."initialPosition": "500300"."scrollbarState": "hidden"
}
Copy the code

Configuration PowerShell

PowerShell can install oh-my-Posh, but I installed Oh-my-zsh on WSL, PowerShell is not the main tool, so I will not configure it separately here, Windows Terminal style is great!

Configuration CentOS 7

CentOS accounts for half of all servers. I choose CentOS because I am familiar with it.

In Windows Terminal, type bash to enter CentOS 7. The default password is root. Type passwd to add a password for root.

Since Linuxbrew needs to be installed and Linuxbrew cannot be run using root, we need to create a user that can use sudo, which we will call admin.

# add user
adduser admin

# set password
passwd admin

Add to wheel user group
usermod -aG wheel admin
Copy the code

After adding, do not rush to switch to the admin user, and do some source configuration work first.

cd /etc/yum.repos.d/

# Update Yum source to domestic Aliyun
mv CentOS-Base.repo CentOS-Base.repo.backup
curl -o CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' CentOS-Base.repo

# generate cache
yum makecache

Install development tools and WGET
yum install -y wget

# increase Epel
wget http://mirrors.aliyun.com/repo/epel-7.repo

# increase IUS
wget https://mirrors.aliyun.com/ius/ius-7.repo
wget https://mirrors.aliyun.com/ius/ius-archive-7.repo
wget https://mirrors.aliyun.com/ius/ius-testing-7.repo

# regenerate the cache
yum makecache

Git 2.x
yum install -y git224

# installation Zsh
yum install -y zsh
Copy the code

Now that you’re done, switch to the admin user and install oh-my-zsh and Homebrew.

Switch to admin
su admin

Oh - my - ZSH # installation
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# to install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Copy the code

After the installation is complete, configure the Zsh as required. ZSHRC in the /home/admin/.zshrc configuration file.

Here is my rough configuration:

Set environment variables
export PATH="$HOME/.linuxbrew/Homebrew/sbin:$HOME/.linuxbrew/Homebrew/bin:$PATH:$(yarn global bin):$HOME/.config/yarn/global/node_modules/.bin"
export ZSH="$HOME/.oh-my-zsh"

Brew locale setup error ignored
export HOMEBREW_NO_ENV_FILTERING=1

# set proxy
exportHttp_proxy = http://192.168.1.111:10809exportHttps_proxy = http://192.168.1.111:10809# Set the theme
ZSH_THEME="gitster"

# setup plugin
plugins=(brew colored-man-pages colorize command-not-found common-aliases dirhistory dotenv dnf emoji emoji-clock encode64 extract git gitfast git-extras git-flow git-flow-avh git-hubflow git-prompt github gitignore history-substring-search jsontools man node npm npx pip python sudo systemd urltools vi-mode vim-interaction yarn yum zsh-autosuggestions zsh-completions zsh_reload zsh-navigation-tools)

# zsh-completions
autoload -U compinit && compinit

Oh - my - ZSH # load
source $ZSH/oh-my-zsh.sh

# set directive alias
alias vi="vim"
alias code="code-insiders"
alias a="code-insiders"
Copy the code

As you can see above, I added Homebrew environment variables, so that you can easily use brew command, and I also installed Yarn, please see install Yarn.

After Homebrew is installed, run Brew Doctor to self-check to see where changes need to be made.

There are a number of plugins and Themes for oh-my-zsh, and plugins can be found in plugins=() of zsh-users. Activate the configuration restart the terminal or type source. ZSHRC.

To improve the installation speed of the nodeJS dependency package, you can set the installation source to Taobao, and the NPM and YARN configuration files to.npmrc and.yarnrc respectively. The files are stored in the root directory of the current user, which is /home/admin/.

.npmrc

registry=https://registry.npm.taobao.org/
disturl=https://npm.taobao.org/dist
chromedriver_cdnurl=https://cdn.npm.taobao.org/dist/chromedriver
phantomjs_cdnurl=https://cdn.npm.taobao.org/dist/phantomjs
sass_binary_site=https://cdn.npm.taobao.org/dist/node-sass
electron_mirror=https://npm.taobao.org/mirrors/electron/
fse_binary_host_mirror=https://npm.taobao.org/mirrors/fsevents
scripts-prepend-node-path=true
Copy the code

.yarnrc

registry "https://registry.npm.taobao.org"
chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"
disturl "https://npm.taobao.org/dist"
electron_mirror "https://npm.taobao.org/mirrors/electron/"
fse_binary_host_mirror "https://npm.taobao.org/mirrors/fsevents"
phantomjs_cdnurl "https://cdn.npm.taobao.org/dist/phantomjs"
sass_binary_site "https://cdn.npm.taobao.org/dist/node-sass"
scripts-prepend-node-path true
Copy the code

3, use,

Windows Terminal can split panes. The command line parameters can be seen here. The command header looks like this:

wt.exe -d "E:\CODE\Project1" yarn.cmd dev `; sp -H -d "E:\CODE\Project2" yarn.cmd dev `; sp -V -d "E:\CODE\Project3" wsl ./http.sh `; sp -H -d "E:\CODE\Project4" wsl ./http.sh
Copy the code

The default value

After the personalized configuration is complete, you can use it. The default startup directory startingDirectory needs to be changed to admin.

Go to the directory where CentOS7 is installed (C:\CentOS7 is used as an example), open Windows Terminal, and type the following command:

Set the default user
.\CentOS7.exe config --default-user admin

Set the default terminal window
.\CentOS7.exe config --default-term wt
Copy the code

In addition, you can also configure the default Terminal defaultProfile in Windows Terminal. For example, I configured PowerShell 7.

If you have Git for Windows installed, the default sh file opening mode is git-bash. There may be some execution permissions issues, just change the opening mode to PowerShell 7.

If the PWSH option is not available, press ↓ -> To find other apps on this PC. Then click the address bar and paste the installation directory of PowerShell 7. For example, C:\Program Files\PowerShell\7, select pwsh.exe, open it and apply it.

Command execution

Because it is WSL, CentOS 7 terminal can call the commands in Windows environment variables. If the suffixed commands exist, such as nginx.exe and yarn.cmd, the corresponding commands in Windows can be run. Do not add suffix, according to the order of search execution, does not exist error message.

For example, to check the node version, node -v runs CentOS 7, and node.exe -v runs Windows.

You can view the command position and which command is executed by typing where < command > and which < command >, for example, to view YARN:

WSL will mount Windows drive letters by default. To facilitate access to Windows drive letters, you can set a directory soft connection, so that you can not type/MNT /< drive letter >, directly /< drive letter > :

sudo ln -s /mnt/* /
Copy the code

right-clicking

Sometimes you don’t want to perform the operation of open terminal -> open directory -> copy directory path -> CD to enter directory -> run the command, then you need to use the right button menu to open the registry, the following is the code, save as shell. Reg, double-click the registry to right-click, and then right-click in the open directory, Click CentOS Here or Powershell Here to start the terminal and locate the current directory.

The terminal.ico icon is downloaded here and placed in the current Windows user directory (% userProfile %).

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell]

[HKEY_CLASSES_ROOT\Directory\Background\shell\centos]
"Icon"="%userprofile%\\terminal.ico"
@="CentOS Here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\centos\command]
@="wt -p CentOS7 -d %v"

[HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell_2]
@="Powershell Here"
"Icon"="pwsh.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell_2\command]
@="wt -p PowerShell7 -d %v"
Copy the code

That’s about it. There’s more to it. I’m groping.

4. Reference reading

  • developer.aliyun.com/mirror
  • npm.taobao.org/mirrors
  • Docs.microsoft.com/zh-cn/windo…
  • Docs. Brew. Sh/Homebrew – on…
  • ohmyz.sh
  • www.how2shout.com/how-to/inst…
  • Phoenixnap.com/kb/how-to-c…