前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Windows Terminal配置 与 添加PowerShell Core

Windows Terminal配置 与 添加PowerShell Core

作者头像
yiyun
发布2022-04-01 15:09:38
1.2K0
发布2022-04-01 15:09:38
举报
文章被收录于专栏:yiyun 的专栏

准备

配置 Windows Terminal

打开Settings,编辑settings.json,为 PowerShell Core 先生成一个GUID,比如用 Online GUID Generator

在 list 中添加一项,如下:

代码语言:javascript
复制
{
    "guid": "{be8c6241-aafb-437f-8d7c-a7142adf7f54}",
    "name": "PowerShell Core",
    "commandline": "D:\\Program Files\\PowerShell\\7\\pwsh.exe",
    "icon": "D:\\Program Files\\PowerShell\\7\\assets\\ps_black_32x32.ico",
    "hidden": false
},

注意:更改 commandline,icon 路径为你的安装路径

添加 Windows Terminal 到右键菜单

注意: 新版安装后会自动添加到右键菜单, 已经不再需要手动添加 创建txt文件,内容为下方,注意:icon图标地址,与 yiyun 用户名 需修改 修改文件名为 添加右键菜单.reg,双击运行即可

代码语言:javascript
复制
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows Terminal here"
"Icon"="F:\\Com\\tools\\WindowsTerminal\\terminal.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="C:\\Users\\yiyun\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

完整配置参考

代码语言:javascript
复制
// This file was initially generated by Windows Terminal 1.1.2021.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.
      "acrylicOpacity": 0.9,
      "colorScheme": "Dark+",
      "fontFace": "DejaVu Sans Mono for Powerline",
      "hidden": false,
      "useAcrylic": false, //true,
      "startingDirectory": "." // 起始目录为当前打开目录
      // "backgroundImage": "F://Com//tools//WindowsTerminal//background.gif",  // 图片地址
      // "backgroundImageOpacity" : 0.15,    // 透明度
      // "backgroundImageStretchMode": "fill" // 填充模式
    },
    "list": [
      {
        "guid": "{be8c6241-aafb-437f-8d7c-a7142adf7f54}",
        "name": "PowerShell Core",
        "commandline": "D:\\Program Files\\PowerShell\\7\\pwsh.exe",
        "icon": "D:\\Program Files\\PowerShell\\7\\assets\\ps_black_32x32.ico",
        "hidden": false
      },
      {
        // 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": "命令提示符",
        "commandline": "cmd.exe",
        "hidden": false
      },
      {
        "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
        "hidden": false,
        "name": "Azure Cloud Shell",
        "source": "Windows.Terminal.Azure"
      },
      {
        "guid": "{4c18d1cd-6d8d-426a-be2f-a4b3152a32c4}",
        "hidden": false,
        "name": "Python 3.8.6rc1",
        "commandline": "D:\\Program Files\\python38\\python.exe",
        "icon": "D:\\Program Files\\python38\\DLLs\\pyc.ico"
      },
      {
        "guid": "{1c4de342-38b7-51cf-b940-2309a097f589}",
        "hidden": false,
        "name": "Git Bash",
        "commandline": "D:\\Program Files\\Git\\bin\\bash.exe",
        "acrylicOpacity": 0, // 透明度
        "closeOnExit": true, // 关闭的时候退出命令终端
        "cursorColor": "#FFFFFF", // 光标颜色
        "cursorShape": "bar", // 光标形状
        "fontFace": "YaHei Consolas Hybrid", // 字体配置,选择你电脑上已安装的字体
        "fontSize": 14, // 终端字体大小
        "icon": "D:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico", // git的图标
        "historySize": 9001, // 终端窗口记忆大小
        "padding": "0, 0, 0, 0", // 边距
        "snapOnInput": true,
        "useAcrylic": false // 是否开启透明度
      }
    ]
  },

  // Add custom color schemes to this array.
  // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
  "schemes": [
    {
      "name": "Japanesque",
      "black": "#343935",
      "red": "#cf3f61",
      "green": "#7bb75b",
      "yellow": "#e9b32a",
      "blue": "#4c9ad4",
      "purple": "#a57fc4",
      "cyan": "#389aad",
      "white": "#fafaf6",
      "brightBlack": "#595b59",
      "brightRed": "#d18fa6",
      "brightGreen": "#767f2c",
      "brightYellow": "#78592f",
      "brightBlue": "#135979",
      "brightPurple": "#604291",
      "brightCyan": "#76bbca",
      "brightWhite": "#b2b5ae",
      "background": "#1e1e1e",
      "foreground": "#f7f6ec"
    },
    {
      "name": "Snazzy",
      "black": "#000000",
      "red": "#fc4346",
      "green": "#50fb7c",
      "yellow": "#f0fb8c",
      "blue": "#49baff",
      "purple": "#fc4cb4",
      "cyan": "#8be9fe",
      "white": "#ededec",
      "brightBlack": "#555555",
      "brightRed": "#fc4346",
      "brightGreen": "#50fb7c",
      "brightYellow": "#f0fb8c",
      "brightBlue": "#49baff",
      "brightPurple": "#fc4cb4",
      "brightCyan": "#8be9fe",
      "brightWhite": "#ededec",
      "background": "#1e1f29",
      "foreground": "#ebece6"
    },
    {
      "name": "Dark+",
      "black": "#000000",
      "red": "#cd3131",
      "green": "#0dbc79",
      "yellow": "#e5e510",
      "blue": "#2472c8",
      "purple": "#bc3fbc",
      "cyan": "#11a8cd",
      "white": "#e5e5e5",
      "brightBlack": "#666666",
      "brightRed": "#f14c4c",
      "brightGreen": "#23d18b",
      "brightYellow": "#f5f543",
      "brightBlue": "#3b8eea",
      "brightPurple": "#d670d6",
      "brightCyan": "#29b8db",
      "brightWhite": "#e5e5e5",
      "background": "#0e0e0e",
      "foreground": "#cccccc"
    }
  ],

  // Add custom keybindings to this array.
  // To unbind a key combination from your defaults.json, set the command to "unbound".
  // To learn more about keybindings, visit https://aka.ms/terminal-keybindings
  "keybindings": [
    // 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"
    }
  ]
}

备份 background.gif

Q&A

补充

git log, git diff 中文乱码(Hex码)

PowerShell 执行下方

代码语言:javascript
复制
git config --global core.quotepath false
git config --global gui.encoding utf-8
git config --global i18n.commit.encoding utf-8
git config --global i18n.logoutputencoding utf-8
$env:LESSCHARSET='utf-8'

添加系统环境变量

点击Ok ,完成后,关闭 Windows Terminal,重新打开,输入下方命令验证是否成功

代码语言:javascript
复制
$env:LESSCHARSET

解决,无论是 git log,还是 git diff, 中文都显示正常

rz

参考:

暂时不支持

添加 SSH 连接

代码语言:javascript
复制
{
    "guid": "{4360b1d2-9732-4bfd-8967-93338bcbb568}",
    "hidden": false,
    "name": "Aliyun ECS",
    "commandline": "ssh root@120.55.193.95",
    "icon": "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png"
}

参考

感谢帮助!

本文作者: yiyun

本文链接: https://cloud.tencent.com/developer/article/1970678

版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-01-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 准备
  • 配置 Windows Terminal
  • 添加 Windows Terminal 到右键菜单
  • 完整配置参考
  • Q&A
  • 补充
    • git log, git diff 中文乱码(Hex码)
      • rz
        • 添加 SSH 连接
        • 参考
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档