Windows Terminal安裝並美化

介紹

Windows Teminal是一款新式、快速、高效、強大的終端應用程序,適用於命令行工具、命令提示符、PowerShell、WSL(Linux子系統)等等的Shell用戶,主要功能包括多選項卡、窗格、Unicode/UTF-8字符支持、GPU 加速文本渲染引擎,以及自定義主題、樣式和配置等等。git

Github地址:https://github.com/microsoft/terminalgithub

官網下載地址:https://www.microsoft.com/zh-cn/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtabshell

安裝Windows Terminal

打開Microsoft Store,搜索Windows Teminal並安裝。json

image-20200521134914481

啓動:ubuntu

image-20200521135414845

安裝最新版本PowerShell

Widows 10 默認是 Windows PowerShell 是 5.X 版本,在 Win10 V1903 以上版本後,打開 PowerShell 時,會提示 「嘗試新的跨平臺 PowerShell https://aka.ms/pscore6」 ,打開提示網址。windows

下載地址:https://github.com/PowerShell/PowerShell/releasesbash

選擇PowerShell-<version>-win-<os-arch>.msi格式的安裝包:工具

image-20200521140127047

下載後,雙擊安裝程序並按照提示進行操做。oop

安裝程序在 Windows「開始」菜單中建立一個快捷方式。ui

  • 默認狀況下,包安裝位置爲 $env:ProgramFiles\PowerShell\
  • 能夠經過「開始」菜單或 $env:ProgramFiles\PowerShell\\pwsh.exe 啓動 PowerShell

PowerShell 7 安裝到新目錄,並與 Windows PowerShell 5.1 並行運行。 對於 PowerShell Core 6.x,PowerShell 7 是刪除 PowerShell Core 6.x 的就地升級。

  • PowerShell 7 安裝到 $env:ProgramFiles\PowerShell\7
  • $env:ProgramFiles\PowerShell\7 文件夾已添加到 $env:PATH
  • $env:ProgramFiles\PowerShell\6 文件夾已刪除

若是須要與 PowerShell 7 並行運行 PowerShell 6,請使用 ZIP 安裝方法從新安裝 PowerShell 6。

查看版本,在命令行窗口中輸入命令

$PSVersionTable.PSVersion

image-20200521144945707

美化Windows Terminal

參考:https://docs.microsoft.com/zh-cn/windows/terminal/

默認會話爲Power Shell 5.x版本,將之修改成7

"defaultProfile":的值改成"source": "Windows.Terminal.PowershellCore"的guid便可,例如它的guid爲"{574e775e-4f2a-5b96-ac1e-a2962a402336}"

"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",

schemes配置

{
				"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"
		}

安裝oh-my-posh

Github地址:https://github.com/JanDeDobbeleer/oh-my-posh

安裝 posh-git 和 oh-my-posh

Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Install-Module DirColors

設置 Powershell 的 profile

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

粘貼如下內容進 profile 文件

Import-Module posh-git
Import-Module oh-my-posh
Import-Module DirColors

主題顏色美化

安裝colortool

scoop install colortool

查看顏色方案

colortool -s

設置顏色:

colortool OneHalfDark.itermcolors

Power Shell 7美化

Power Shell 7的配置:

{
                "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
                "hidden": false,
                "name": "PowerShell",
                "source": "Windows.Terminal.PowershellCore",
                "colorScheme" : "Snazzy",
                "startingDirectory": "E:\\",
				"fontFace" : "Cascadia Code PL",
                "cursorColor" : "#000000"
            }

顯示效果以下:

image-20200522172316104

image-20200522223713868

ubuntu美化

Power Shell 7的配置:

{
                "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
                "hidden": false,
                "name": "Ubuntu-20.04",
				"colorScheme" : "Snazzy",
                "startingDirectory": "E:\\code",
                "source": "Windows.Terminal.Wsl"
            },

修改命令提示符,修改root用戶的~/.bashrc文件:

export PS1='\[\e[31;1m\][\u\[\e[37;1m\]@\[\e[34;1m\]\H \W]\[\e[35;1m\]\$ \[\e[0m\]'

新建/etc/profile.d/ps1.sh

export PS1='\[\e[36;1m\][\u\[\e[33;1m\]@\[\e[35;1m\]\H \W]\[\e[34;1m\]\$ \[\e[0m\]'

新建/etc/profile.d/alias.sh

alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'

顯示效果以下:

image-20200522181227825

相關文章
相關標籤/搜索