terminal 实践

常用字体

links:

powershell

下载 Powershell、Windows terminal,并设置透明度及默认的 shell 为 PS。

修改颜色,复制 One Half Dark,并修改名称 One Half Dark (moded) 颜色为#001B26

修改字体类 Nerd Font,推荐 JetBrain Mono

配置 PS 命令脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
choco install neovim grep
choco install JetBrainsMonoNF
# 创建自定义脚本
nvim .config/powershell/user_profile.ps1

# 添加脚本
PS C:\Users\msclo> cat .\.config\powershell\user_profile.ps1
# Alias

Set-Alias vim nvim
Set-Alias ll ls
Set-Alias g git
Set-Alias less 'C:\Program Files\Git\usr\bin\less.exe'

# 生效 profile
nvim $PROFILE
# 添加 profile
C:\Users\msclo> cat $PROFILE
. $env:USERPROFILE\.config\powershell\user_profile.ps1


# posh-git
Install-Module posh-git -Scope CurrentUser -Force

# omp,参考 https://ohmyposh.dev/
choco install/upgrade oh-my-posh

# 配置 omp 到 user_profile.ps1
Set-Alias oh-my-posh 'C:\Program Files (x86)\oh-my-posh\bin\oh-my-posh'
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/takuya.omp.json" | Invoke-Expression

# terminal icons,添加到 user_profile.ps1 中
Install-Module -Name Terminal-Icons -Repository PSGallery -Force

# Z,跟踪常用目录自动跳转
Install-Module -Name Z -Force

# PSReadline,跟踪历史命令
Install-Module -Name PSReadline -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
Set-PSReadlineOption -PredictionSource History
Set-PSReadlineOption -PredictionViewStyle ListView

# fzf,历史命令查找
choco install fzf
Install-Module -Name PSFzf -Force
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+f' -PSReadlineChordReversedHistory 'Ctrl+r'

最终完整 user_profile.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Prompt

# git
Import-Module posh-git

# Icons
Import-Module Terminal-Icons

# oh-my-posh
Set-Alias oh-my-posh 'C:\Program Files (x86)\oh-my-posh\bin\oh-my-posh'
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/takuya.omp.json" | Invoke-Expression

# PSReadline history
Set-PSReadlineOption -BellStyle None
Set-PSReadlineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
Set-PSReadlineOption -PredictionSource History
Set-PSReadlineOption -PredictionViewStyle ListView

# Fzf
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+f' -PSReadlineChordReversedHistory 'Ctrl+r'

# Alias
Set-Alias vim nvim
Set-Alias ll ls
Set-Alias g git
Set-Alias less 'C:\Program Files\Git\usr\bin\less.exe'

# Utilities
function which ($command){
Get-Command -Name $command -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}

# Watch
function Watch-Command {
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='High')]
param (
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$command,

[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[int]$interval = 2
)
process {
$cmd = [scriptblock]::Create($command);
While($True) {
$output = $cmd.Invoke();
cls;
Write-Host "Command: " $command;
Write-Host ($output | Out-String);
sleep $interval;
}
}
}

iwr

powershell 下类似 curl 工具命令

1
2
3
4
5
6
7
8
# 下载文件
iwr https://example.com/file.zip -OutFile file.zip

# 获取网页内容
iwr https://example.com/page.html

# 将响应保存到变量中
$response = iwr https://example.com/api/data -UseBasicParsing

net

显示连接过的 wifi 密码

1
2
netsh wlan show profiles
netsh wlan show profiles name="wifi name" key=clear

显示 ip

1
2
ipconfig /all
curl -L ip.tool.lu

检验网络连通

1
ping pi address -t

连接远程桌面

1
mstsc

disk

检验磁盘扇区

1
2
3
chkdsk
# 进行修复
chkdsk /r

打开性能监控

1
perform.msc

net

1
2
3
4
# list all user
net user
# del user
net user [user-name] /del

sfc

1
sfc /scannow

服务

1
2
3
4
sc create ceshi binpath= D:\ceshi\ceshi.exe type= own start= auto displayname= ceshi
net start ceshi
net stop ceshi
sc delete "ceshi"

zsh

资源 组织 类型
awesome-zsh-plugins unixorn zsh plugins
devcontainer zsh-plugins devcontainers-contrib devcontainer zsh plugins
ohmyzsh themes ohmyzsh themes

zsh

通过 devcontainer 插件安装 zsh

1
git clone --depth 1 https://github.com/devcontainers/features.git && CONFIGURE_ZSH_AS_DEFAULT_SHELL=true USERNAME=$USER ./features/src/common-utils/install.sh

fzf

Usage

Install

1
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf

links: