Powershell 与 Windows Terminal

Table of Contents

1. Powershell

找到 Profile 位置1code $Home\Documents\PowerShell\Profile.ps1

1.1. PSColor:目录、文件支持 color

https://github.com/Davlind/PSColor

  1. 安装 Install-Module PSColor -Proxy "http://127.0.0.1:7890"
  2. Profile 中添加 Import-Module PSColor

1.2. PowerLine - Beautiful, Powerful, PowerShell prompts

https://github.com/Jaykul/PowerLine

  1. 安装

    Install-Module PANSIES -AllowClobber -Proxy "http://127.0.0.1:7890"
    Install-Module PowerLine -Proxy "http://127.0.0.1:7890"
    
  2. Profile 中添加 Import-Module PowerLine
  3. 首次执行使用 Set-PowerLinePrompt -SetCurrentDirectory -RestoreVirtualTerminal -Newline -Timestamp -Colors "#FFDD00", "#FF6600"

1.3. posh-git:git 命令行增强

https://github.com/dahlbyk/posh-git

  1. 安装 Install-Module posh-git -Scope CurrentUser -Force -Proxy "http:/127.0.0.1:7890"
  2. Profile 中添加 Import-Module posh-git

注意 posh-git 和 PowerLine 只能用一个。

1.4. Commands Cheat Sheet

命令 说明
=Remove-Item -Recurse -Force <path> = 强制删除

2. Windows Terminal

https://docs.microsoft.com/zh-cn/windows/terminal/get-started ,直接在商店搜索 Perviews 版本使用。

Windows terminal 快捷键跟 Emacs 快捷键冲突很多,索性直接禁用掉:

{
    "command": "unbound",
    "keys": "ctrl+v"
},
{
    "command": "unbound",
    "keys": "ctrl+c"
},
{
    "command": "unbound",
    "keys": "ctrl+shift+f"
},
{
    "command": "unbound",
    "keys": "alt+shift+d"
},
{
    "command": "unbound",
    "keys": "ctrl+shift+space"
},
{
    "command": "unbound",
    "keys": "ctrl+comma"
},
{
    "command": "unbound",
    "keys": "ctrl+shift+comma"
},
{
    "command": "unbound",
    "keys": "ctrl+alt+comma"
},
{
    "command": "unbound",
    "keys": "alt+space"
},
{
    "command": "unbound",
    "keys": "alt+enter"
},

重新绑定页签切换快捷键:

{
    "command":
    {
        "action": "switchToTab",
        "index": 2
    },
    "keys": "alt+3"
},
{
    "command":
    {
        "action": "switchToTab",
        "index": 0
    },
    "keys": "alt+1"
},
{
    "command":
    {
        "action": "switchToTab",
        "index": 1
    },
    "keys": "alt+2"
},
{
    "command":
    {
        "action": "switchToTab",
        "index": 3
    },
    "keys": "alt+4"
}

光标颜色 在配置文件 profiles -> defaults 下面添加 "cursorColor": "#ec0"

3. FAQ

3.1. Powershell cat 文件时,中文乱码

需要加上 -Encoding UTF8 ,即 cat .\xxx.txt -Encoding UTF82

Footnotes:

First created:
Last updated: 2022-12-11 Sun 12:49
Power by Emacs 29.0.91 (Org mode 9.6.6)