像MAC一样使用win10的Terminal(精简版)

之前写了《像MAC一样使用win10的Terminal》,因为里面写的内容过于复杂,评论里会有很多人提问,现在根据Windows 10 1909版本,出个更简单的方式。

废话不多说,上图:


美化后的Windows Terminal

一. 安装

直接进入Microsoft Store:


Windows Terminal

二. 复制我的配置文件

使用notepad $PROFILE即可打开

注意:如果没有$PROFILE文件的话,可以先执行:

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

然后notepad $PROFILE,粘贴我的配置:

Import-Module Get-ChildItemColor

$env:PYTHONIOENCODING="utf-8"
# Remove curl alias
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
# Remove-Item alias:ls -force
Set-Alias l Get-ChildItemColor -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope

function GitLogPretty {
  git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all
}

function PrettyLS {
  colorls --light -A
}

function GitStat {git status}

function GoBack {Set-Location ..}

function GetMyIp {curl -L tool.lu/ip}
function UpdateScoop {scoop update; scoop update *}

function UpdateChoco {choco upgrade chocolatey}

Import-Module posh-git
Import-Module oh-my-posh
# $DefaultUser = 'spenc'

# Setup other alias
Set-Alias open Invoke-Item
Set-Alias .. GoBack
Set-Alias glola GitLogPretty
Set-Alias gst GitStat
Set-Alias myip GetMyIp
Set-Alias pls PrettyLS

# Set theme
Set-Theme robbyrussell

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

可能会有提示报错之类的,不急,我们再继续安装关联的内容。
因为我的1909版本还没有winget,所以还是使用ScoopChoco来安装相关信息

三.安装Scoop

  1. 访问Scoop官网

  2. 安装

Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

# 或者使用精简命令安装
iwr -useb get.scoop.sh | iex

如果安装报错,请先执行下面操作

Set-ExecutionPolicy RemoteSigned -scope CurrentUser

四. 安装字体

如果没安装这种字体,后边安装样式的时候,会有乱码情况

Fantasque Sans Mono Nerd Font

# 搜索 nerd fonts,这里选择是的FantasqueSansMono这个字体
scoop search FantasqueSansMono-NF
# 添加 nerd fonts 源
scoop bucket add 'nerd-fonts'
# 安装 nerd fonts
scoop install FantasqueSansMono-NF

注意:
这里可能会提示安装git,用scoop install git就行了。
另外,如果安装一半失败了,记得一定要先scoop uninstall xx,再进行scoop install xxx

五. 安装 Choco

  1. 以管理员方式运行Windows Terminal 或者 Power Shell

  2. 执行命令

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

六. 安装oh-my-posh(类似oh-my-zsh

  1. 安装 posh-gitoh-my-posh
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
  1. 如果没有使用我的配置,请粘贴以下内容进 PROFILE 文件
Import-Module posh-git
Import-Module oh-my-posh
# 设置样式Paradox
Set-Theme Paradox

参考:

  • 《posh-git: A PowerShell environment for Git》
  • 《oh-my-posh: A prompt theming engine for Powershell》

到这里,就已经基本结束了。

因为我的配置里有对ls命令的绑定,所以,还得优化一下ls效果

七. 优化ls命令

  1. 安装get-childitemcolor
choco install get-childitemcolor
  1. 引用get-childitemcolor
Import-Module Get-ChildItemColor

参考:
《ChildItemColor: Add coloring to the output of Get-ChildItem Cmdlet of PowerShell》

这样,就正式的全部搞定了!

八. 如果想跟我的样式一模一样,还需要Window Terminal的配置改一下

主要就是对每个Ternimal设置面板新式:

"fontFace" : "Cascadia Code",  // 字体
"useAcrylic": true, // 是否开启透明度
"acrylicOpacity": 0.7,  // 面板透明度
"colorScheme": "One Half Dark",  // 颜色主题
"backgroundImageOpacity" : 0.3,  // 背景图片透明度(我这里是预留的,我没有设置背景图片)
"backgroundImageStretchMode" : "fill"  // 背景图片填充方式

注意:
想要半透明效果的前提是系统已经开启了半透明,如图:


系统开启半透明效果

不想折腾的,直接复制我的配置:

// This file was initially generated by Windows Terminal 1.4.3243.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

    // You can add more global application settings here.
    // To learn more about global settings, visit https://aka.ms/terminal-global-settings

    // If enabled, selections are automatically copied to your clipboard.
    "copyOnSelect": false,

    // If enabled, formatted data is also copied to your clipboard
    "copyFormatting": false,

    // A profile specifies a command to execute paired with information about how it should look and feel.
    // Each one of them will appear in the 'New Tab' dropdown,
    //   and can be invoked from the commandline with `wt.exe -p xxx`
    // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false,
                "fontFace" : "Cascadia Code",
                "useAcrylic": true,
                "acrylicOpacity": 0.7,
                "colorScheme": "One Half Dark",
                "backgroundImageOpacity" : 0.3,
                "backgroundImageStretchMode" : "fill"
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "Command Prompt",
                "commandline": "cmd.exe",
                "hidden": false,
                "fontFace" : "Cascadia Code",
                "useAcrylic": true,
                "acrylicOpacity": 0.9,
                "colorScheme": "One Half Dark",
                "backgroundImageOpacity" : 0.3,
                "backgroundImageStretchMode" : "fill"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure",
                "fontFace" : "Cascadia Code",
                "useAcrylic": true,
                "acrylicOpacity": 0.9,
                "colorScheme": "One Half Dark",
                "backgroundImageOpacity" : 0.3,
                "backgroundImageStretchMode" : "fill"
            }
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [],

    // Add custom actions and keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
    "actions":
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
        { "command": "paste", "keys": "ctrl+v" },

        // Press Ctrl+Shift+F to open the search box
        { "command": "find", "keys": "ctrl+shift+f" },

        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
    ]
}

相关工具

  • The PS1 variable
  • ColorTool
  • Nerd fonts
  • Github:Nerd fonts
  • Dracula
  • Dotfiles
  • Get-ChildItemColor
  • Iterm2-color-schemes
  • FluentTerminal
  • chocolatey:Same as Homebrew-Cask
  • scoop:Same as Homebrew
  • oh-my-posh

你可能感兴趣的:(像MAC一样使用win10的Terminal(精简版))