超简单实用window终端(前端用)

537 阅读2分钟

效果

安装powershell7.x

安装windows terminal

  • 去Microsoft store中下载
  • 打开terminal 进入设置 请酌情复制(免得麻烦就全部cv) 注意一下我中文注释的那几段就行了
// 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",
	// 默认启动的终端guid
  "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",

  // 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.
      "startingDirectory": "./",
      "useAcrylic": true,
      // 终端透明度
      "acrylicOpacity": 0.8
    },
    "list": [
      {
        "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
        "hidden": false,
        "name": "ps7",
        "source": "Windows.Terminal.PowershellCore",
        //终端中使用的字体
        "fontFace": "FiraCode Nerd Font",
        "historySize": 9001,
        "padding": "5, 5, 20, 25",
        "snapOnInput": true,
        "colorScheme": "Andromeda"
      },
      {
        // Make changes here to the powershell.exe profile.
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
        "name": "Windows PowerShell",
        "commandline": "powershell.exe",
        "hidden": false
      },
      {
        // Make changes here to the cmd.exe profile.
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
        "name": "Command Prompt",
        "commandline": "cmd.exe",
        "hidden": false
      },
      {
        "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
        "hidden": false,
        "name": "Ubuntu",
        "source": "Windows.Terminal.Wsl"
      },
      {
        "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
        "hidden": false,
        "name": "Azure Cloud Shell",
        "source": "Windows.Terminal.Azure"
      }
    ]
  },

  // Add custom color schemes to this array.
  // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
  // 终端配色
  "schemes": [
    {
      "name": "Andromeda",
      "black": "#000000",
      "red": "#cd3131",
      "green": "#05bc79",
      "yellow": "#e5e512",
      "blue": "#2472c8",
      "purple": "#bc3fbc",
      "cyan": "#0fa8cd",
      "white": "#e5e5e5",
      "brightBlack": "#666666",
      "brightRed": "#cd3131",
      "brightGreen": "#05bc79",
      "brightYellow": "#e5e512",
      "brightBlue": "#2472c8",
      "brightPurple": "#bc3fbc",
      "brightCyan": "#0fa8cd",
      "brightWhite": "#e5e5e5",
      "background": "#262a33",
      "foreground": "#e5e5e5"
    }
  ],

  // 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"
    }
  ]
}
  • 安装字体FiraCode Nerd Font终端中的些许特殊字体符号就是在这个名下

安装scoop

iwr -useb get.scoop.sh | iex
  • 安装 colortool starship 如果安装不成功请多试几次如果不行选个早上安装,感觉快点
scoop install colortool
scoop install starship
  • 配置powershell,以下命令都在powershell7中完成 touch命令提示不存在的话配置好shell,然后重新打开shell 推荐用vscode打开,其他的打开也行,都一个意思
code $Profile
#-----------------------------------------------------PSReadline
# 设置 Tab 键补全
Set-PSReadlineKeyHandler -Key Tab -Function Complete

# 设置 Ctrl+d 为菜单补全和 Intellisense
# Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete

# 设置 Ctrl+d 为退出 PowerShell
# Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit

# 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo

# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward

# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

# 一些PSReadline配置
$PSReadLineOptions = @{
    EditMode                      = "Emacs"
    HistoryNoDuplicates           = $true
    HistorySearchCursorMovesToEnd = $true
    # Colors                        = @{
    #     # 提示文字颜色,原来的颜色太浅了,我这里换了
    #     Prediction = '#8F8B8B'
    # }
}
Set-PSReadLineOption @PSReadLineOptions

#-----------------------------------------------------starship
Invoke-Expression (&starship init powershell)

# 设置touch 创建新文件
function touch {
    Param(
        [Parameter(Mandatory = $true)]
        [string]$Path
    )
  
    if (Test-Path -LiteralPath $Path) {
        (Get-Item -Path $Path).LastWriteTime = Get-Date
    }
    else {
        New-Item -Type File -Path $Path
    }
}
# 有能力的话可以研究下这边的函数命令

没有vscode的话 可以选择对应的文件修改 文件位置在对应的下面的位置 注意UserName 我的路径不一样 C:\Users\UserName\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json

  • 配置starship
mkdir -p ~/.config && touch ~/.config/starship.toml
  • 若创建失败 证明.config目录已存在直接在下面新建starship.toml文件
touch ~/.config/starship.toml
  • 用vscode 编辑starship这个文件 请无脑复制 我也是无脑复制别人的 大致意思稍微观察一下就知道
[character]      
symbol = "➜"    

[aws]
symbol = " "

[battery]
full_symbol = ""
charging_symbol = ""
discharging_symbol = ""

[conda]
symbol = " "

[docker]
symbol = " "

[elixir]
symbol = " "

[elm]
symbol = " "

[git_branch]
symbol = " "

[golang]
symbol = " "

[haskell]
symbol = " "

[hg_branch]
symbol = " "

[java]
symbol = " "

[julia]
symbol = " "

[memory_usage]
symbol = " "

[nix_shell]
symbol = " "

[nodejs]
# symbol = " "
symbol=" "

[package]
symbol = " "

[php]
symbol = " "

[python]
symbol = " "

[ruby]
symbol = " "

[rust]
symbol = " "
 
  • 配置colortool 查看颜色表
colortool -s

选择一款颜色

colortool  OneHalfDark.itermcolors

加入git支持

Install-Module posh-git -Scope CurrentUser -Force
Import-Module posh-git
Add-PoshGitToProfile -AllHosts

这样就可以在powershell里面愉快的使用git了

vscode 终端配置看图

  • 设置终端字体,字体不生效或者奇怪, 请重启vscode

其他终端

上面终端叫做 terminus 自行搜索安装如果有兴趣的话

感谢

参考 windows terminal加powershell7美化命令行操作