文本最后编辑时间:2020-06-04
在这之前,我一直使用的都是cmder,但是这东西说真的,有点难用。不过好在微软推出了Windows Terminal,经过我的实测,感觉还是不错的。毕竟颜值才是第一生产力。
看完上边的三个插件介绍,我们来安装这三个插件。 用管理员模式打开刚装好的新版 powershell,逐行输入命令。 # 1. 安装 PSReadline 包,该插件可以让命令行很好用,类似 zsh Install-Module -Name PSReadLine -AllowPrerelease -Force # 2. 安装 posh-git 包,让你的 git 更好用 Install-Module posh-git -Scope CurrentUser # 3. 安装 oh-my-posh 包,让你的命令行更酷炫、优雅 Install-Module oh-my-posh -Scope CurrentUser
一定要用刚刚安装的新版的powershell,安装过程可能过于慢,请耐心等待。
后面两个包的来源可能不受系统信任,不用管它,如果让你选择是否信任,直接输入 Y
即可。
$Profile
文件。
这个文件类似于 ~/.zshrc
,会在 PowerShell 启动的时候自动执行,因此我们在这个文件中加载我们所需的模块。
notepad.exe $Profile
nano $Profile
然后在这个文件中添加如下内容:
Import-Module posh-git # 引入 posh-git
Import-Module oh-my-posh # 引入 oh-my-posh
Set-Theme Paradox # 设置主题为 Paradox
Set-PSReadlineKeyHandler -Key Tab -Function Complete # 设置 Tab 键补全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 设置 Ctrl+d 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 设置向下键为前向搜索历史纪录
Windows Terminal
。
Windows Terminal默认为旧版本的powershell,我们需要把新版本作为默认。
修改的内容有三个,如果你不想自己改可以直接将我的粘贴到配置文件。
// This file was initially generated by Windows Terminal 1.0.1401.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": "{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.
},
"list": [
{
// 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": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"source": "Windows.Terminal.PowershellCore"
},
{
// Powershell 7.1.0-preview.2 配置
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "pwsh",
// 注意:一定要写上 -nologo,否则开启 powershll 会有一段话输出,很讨厌!
"commandline": "C:/Program Files/PowerShell/7-preview/pwsh.exe -nologo",
"source": "Windows.Terminal.PowershellCore",
// 启动菜单一定要设置为 <.>,否则后面重要的一步将会无效!
"startingDirectory": ".",
// 字体
"fontFace": "Fira Code",
"fontSize": 11,
"historySize": 9001,
"padding": "5, 5, 20, 25",
"snapOnInput": true,
"useAcrylic": false,
// 颜色
"colorScheme": "idleToes"
} ]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [
{
"name": "Zenburn",
"black": "#4d4d4d",
"red": "#705050",
"green": "#60b48a",
"yellow": "#f0dfaf",
"blue": "#506070",
"purple": "#dc8cc3",
"cyan": "#8cd0d3",
"white": "#dcdccc",
"brightBlack": "#709080",
"brightRed": "#dca3a3",
"brightGreen": "#c3bf9f",
"brightYellow": "#e0cf9f",
"brightBlue": "#94bff3",
"brightPurple": "#ec93d3",
"brightCyan": "#93e0e3",
"brightWhite": "#ffffff",
"background": "#3f3f3f",
"foreground": "#dcdccc"
},
{
"name": "PencilDark",
"black": "#212121",
"red": "#c30771",
"green": "#10a778",
"yellow": "#a89c14",
"blue": "#008ec4",
"purple": "#523c79",
"cyan": "#20a5ba",
"white": "#d9d9d9",
"brightBlack": "#424242",
"brightRed": "#fb007a",
"brightGreen": "#5fd7af",
"brightYellow": "#f3e430",
"brightBlue": "#20bbfc",
"brightPurple": "#6855de",
"brightCyan": "#4fb8cc",
"brightWhite": "#f1f1f1",
"background": "#212121",
"foreground": "#f1f1f1"
},
{
"name": "Slate",
"black": "#222222",
"red": "#e2a8bf",
"green": "#81d778",
"yellow": "#c4c9c0",
"blue": "#264b49",
"purple": "#a481d3",
"cyan": "#15ab9c",
"white": "#02c5e0",
"brightBlack": "#ffffff",
"brightRed": "#ffcdd9",
"brightGreen": "#beffa8",
"brightYellow": "#d0ccca",
"brightBlue": "#7ab0d2",
"brightPurple": "#c5a7d9",
"brightCyan": "#8cdfe0",
"brightWhite": "#e0e0e0",
"background": "#222222",
"foreground": "#35b1d2"
},
{
"name": "OneHalfDark",
"black": "#282c34",
"red": "#e06c75",
"green": "#98c379",
"yellow": "#e5c07b",
"blue": "#61afef",
"purple": "#c678dd",
"cyan": "#56b6c2",
"white": "#dcdfe4",
"brightBlack": "#282c34",
"brightRed": "#e06c75",
"brightGreen": "#98c379",
"brightYellow": "#e5c07b",
"brightBlue": "#61afef",
"brightPurple": "#c678dd",
"brightCyan": "#56b6c2",
"brightWhite": "#dcdfe4",
"background": "#282c34",
"foreground": "#dcdfe4"
},
{
"name": "OneHalfLight",
"black": "#383a42",
"red": "#e45649",
"green": "#50a14f",
"yellow": "#c18401",
"blue": "#0184bc",
"purple": "#a626a4",
"cyan": "#0997b3",
"white": "#fafafa",
"brightBlack": "#4f525e",
"brightRed": "#e06c75",
"brightGreen": "#98c379",
"brightYellow": "#e5c07b",
"brightBlue": "#61afef",
"brightPurple": "#c678dd",
"brightCyan": "#56b6c2",
"brightWhite": "#ffffff",
"background": "#fafafa",
"foreground": "#383a42"
},
{
"name": "Material",
"black": "#212121",
"red": "#b7141f",
"green": "#457b24",
"yellow": "#f6981e",
"blue": "#134eb2",
"purple": "#560088",
"cyan": "#0e717c",
"white": "#efefef",
"brightBlack": "#424242",
"brightRed": "#e83b3f",
"brightGreen": "#7aba3a",
"brightYellow": "#ffea2e",
"brightBlue": "#54a4f3",
"brightPurple": "#aa4dbc",
"brightCyan": "#26bbd1",
"brightWhite": "#d9d9d9",
"background": "#eaeaea",
"foreground": "#232322"
},
{
"name": "MaterialDark",
"black": "#212121",
"red": "#b7141f",
"green": "#457b24",
"yellow": "#f6981e",
"blue": "#134eb2",
"purple": "#560088",
"cyan": "#0e717c",
"white": "#efefef",
"brightBlack": "#424242",
"brightRed": "#e83b3f",
"brightGreen": "#7aba3a",
"brightYellow": "#ffea2e",
"brightBlue": "#54a4f3",
"brightPurple": "#aa4dbc",
"brightCyan": "#26bbd1",
"brightWhite": "#d9d9d9",
"background": "#232322",
"foreground": "#e5e5e5"
},
{
"name": "Homebrew",
"black": "#000000",
"red": "#FC5275",
"green": "#00a600",
"yellow": "#999900",
"blue": "#6666e9",
"purple": "#b200b2",
"cyan": "#00a6b2",
"white": "#bfbfbf",
"brightBlack": "#666666",
"brightRed": "#e50000",
"brightGreen": "#00d900",
"brightYellow": "#e5e500",
"brightBlue": "#0000ff",
"brightPurple": "#e500e5",
"brightCyan": "#00e5e5",
"brightWhite": "#e5e5e5",
"background": "#283033",
"foreground": "#00ff00"
},
{
"name": "Breeze",
"black": "#31363b",
"red": "#ed1515",
"green": "#11d116",
"yellow": "#f67400",
"blue": "#1d99f3",
"purple": "#9b59b6",
"cyan": "#1abc9c",
"white": "#eff0f1",
"brightBlack": "#7f8c8d",
"brightRed": "#c0392b",
"brightGreen": "#1cdc9a",
"brightYellow": "#fdbc4b",
"brightBlue": "#3daee9",
"brightPurple": "#8e44ad",
"brightCyan": "#16a085",
"brightWhite": "#fcfcfc",
"background": "#31363b",
"foreground": "#eff0f1"
},
{
"name": "idleToes",
"black": "#323232",
"red": "#d25252",
"green": "#7fe173",
"yellow": "#ffc66d",
"blue": "#4099ff",
"purple": "#f680ff",
"cyan": "#bed6ff",
"white": "#eeeeec",
"brightBlack": "#535353",
"brightRed": "#f07070",
"brightGreen": "#9dff91",
"brightYellow": "#ffe48b",
"brightBlue": "#5eb7f7",
"brightPurple": "#ff9dff",
"brightCyan": "#dcf4ff",
"brightWhite": "#ffffff",
"background": "#323232",
"foreground": "#00ff00"
},
{
"name": "Firewatch",
"black": "#585f6d",
"red": "#d95360",
"green": "#5ab977",
"yellow": "#dfb563",
"blue": "#4d89c4",
"purple": "#d55119",
"cyan": "#44a8b6",
"white": "#e6e5ff",
"brightBlack": "#585f6d",
"brightRed": "#d95360",
"brightGreen": "#5ab977",
"brightYellow": "#dfb563",
"brightBlue": "#4c89c5",
"brightPurple": "#d55119",
"brightCyan": "#44a8b6",
"brightWhite": "#e6e5ff",
"background": "#1e2027",
"foreground": "#9ba2b2"
},
{
"name": "Github",
"black": "#3e3e3e",
"red": "#970b16",
"green": "#07962a",
"yellow": "#f8eec7",
"blue": "#003e8a",
"purple": "#e94691",
"cyan": "#89d1ec",
"white": "#ffffff",
"brightBlack": "#666666",
"brightRed": "#de0000",
"brightGreen": "#87d5a2",
"brightYellow": "#f1d007",
"brightBlue": "#2e6cba",
"brightPurple": "#ffa29f",
"brightCyan": "#1cfafe",
"brightWhite": "#ffffff",
"background": "#f4f4f4",
"foreground": "#3e3e3e"
}
],
// 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"
}
]
}
defaultProfile
将defaultProfile
改为新的powershell。
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",list
在list中新增一个配置,也就是我们的新版powershell。{
// Powershell 7.1.0-preview.2 配置
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "pwsh",
// 注意:一定要写上 -nologo,否则开启 powershll 会有一段话输出,很讨厌!
"commandline": "C:/Program Files/PowerShell/7-preview/pwsh.exe -nologo",
"source": "Windows.Terminal.PowershellCore",
// 启动菜单一定要设置为 <.>,否则后面重要的一步将会无效!
"startingDirectory": ".",
// 字体
"fontFace": "Fira Code",
"fontSize": 11,
"historySize": 9001,
"padding": "5, 5, 20, 25",
"snapOnInput": true,
"useAcrylic": false,
// 颜色
"colorScheme": "idleToes"
},
{
"name": "idleToes",
"black": "#323232",
"red": "#d25252",
"green": "#7fe173",
"yellow": "#ffc66d",
"blue": "#4099ff",
"purple": "#f680ff",
"cyan": "#bed6ff",
"white": "#eeeeec",
"brightBlack": "#535353",
"brightRed": "#f07070",
"brightGreen": "#9dff91",
"brightYellow": "#ffe48b",
"brightBlue": "#5eb7f7",
"brightPurple": "#ff9dff",
"brightCyan": "#dcf4ff",
"brightWhite": "#ffffff",
"background": "#323232",
"foreground": "#00ff00"
},
接下来就是配置鼠标右键了,添加鼠标右键的方式有两种,一种是用脚本,另一种就是改注册表。我本人比较推荐直接使用脚本,毕竟修改注册表有风险。。。
install.ps1
的目录进行安装。我这里使用默认安装。如果你想用其他模式,也可以使用其他模式,看自己心情即可。其他模式请参考项目文档。