Loading

2024年,提升Windows开发和使用体验实践 - 终端&命令行篇

前言

经过前面的铺垫,终于继续更新了,这个大概率是本系列近期的最后一篇了。

同时之前有些内容更新,我也补充到这一篇里面。

关于 scoop 管理器的补充

scoop 常用命令

scoop help # 查看帮助
scoop help < 某个命令 > # 具体查看某个命令的帮助

scoop info <app>      # 查看 APP 信息
scoop install <app>   # 安装 APP
scoop uinstall <app>  # 卸载 APP
scoop reset [app]@[version] # 切换版本

scoop list  # 列出已安装的 APP
scoop search # 搜索 APP
scoop status # 检查哪些软件有更新

scoop update # 更新 Scoop 自身
scoop update appName1 appName2 # 更新某些 app
scoop update *  # 更新所有 app (前提是需要在 apps 目录下操作)

scoop bucket known # 通过此命令列出已知所有 bucket(软件源)
scoop bucket add bucketName # 添加某个 bucket

scoop cache rm <app>  # 移除某个 app 的缓存
scoop cache rm *      # 移除所有缓存
scoop cleanup <app>   # 删除旧版本

scoop 常见问题

安装软件时出现 hash 检查错误

  • 多次安装后仍出现错误,找到其 JSON 文件,下载到本地更改其 hash 值,上传到自己的 bucket 中,进行更新。
  • 使用 scoop install -s 选项以忽略其 hash 检查,具体使用方法请用 scoop help install

更新软件时如何删除旧版本软件

使用 scoop cleanup 命令,具体用法查看 scoop help cleanup

终端

OK,来到 Windows 开发体验的重灾区了

命令行一直以来都是 Windows 的弱势,现在有了一些 Rust 工具链,可以慢慢改善这一现状。

Nerd Fonts

想要美化终端界面,请先安装一个 nerd 字体

这时候包管理器的作用再次体现,使用 scoop 就能安装。

先添加个 bucket

scoop bucket add nerd-fonts

项目地址: https://github.com/matthewjberger/scoop-nerd-fonts

然后选择一个喜欢的字体进行安装

scoop install FiraCode-NF

另外,这个 bucket 里面的字体很多,现在已经不仅仅是 nerd font 了,也可以安装一些普通的字体,比如

scoop install SarasaGothic-SC # 安装更纱黑体(简体中文)
scoop install Wenquanyi-Microhei # 安装文泉驿微米黑
scoop install Wenquanyi-Zenhei # 安装文泉驿正黑

参考资料

内置 Powershell

先说结论:内置的 PowerShell 是垃圾

不推荐使用 oh-my-posh ,启动速度太慢了,本身 PowerShell 的启动速度就慢,加上 oh-my-posh 就更慢了。

终端美化使用 Starship 就行了,接下来会介绍。

编辑配置的方法: nano $PROFILE

这是我的配置

# oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/amro.omp.json" | Invoke-Expression

Import-Module gsudoModule

set-alias -name ll -value ls
set-alias -name ef -value dotnet-ef

# starship
Invoke-Expression (&starship init powershell)
$ENV:STARSHIP_CONFIG = "$HOME\.config\starship\plain-text-symbols.toml"

Powershell 7

这是微软新出的开源跨平台终端,比内置的 PowerShell 的功能强了一丢丢,性能更好。(从项目仓库来看,是使用 C# 开发的,所以跨平台做得不错)

项目地址: https://github.com/PowerShell/PowerShell

下载个安装包安装就完事了

我的 $PROFILE 配置

Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineKeyHandler -Chord Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Key UpArrow -ScriptBlock {
	[Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchBackward()
  [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
}
Set-PSReadLineKeyHandler -Key DownArrow -ScriptBlock {
	[Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchForward()
  [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
}
Set-PSReadLineOption -PredictionViewStyle ListView
set-alias -name ll -value ls

# starship
Invoke-Expression (&starship init powershell)
$ENV:STARSHIP_CONFIG = "$HOME\.config\starship\gruvbox-rainbow.toml"

Starship

NuShell

https://www.nushell.sh/zh-CN/book/

参考资料

命令行工具

WinSW

进程管理工具,类似 Linux 下的 supervisor ,可以将要运行的程序安装成服务,设置自动运行。

安装

scoop install winsw

使用方式

与 supervisor 类似,写配置文件,然后安装服务,可以启动和停止啥的。

我的目录结构

这里我设置了两个服务,vnc 和 frpc

 WinSW
 ├─ config
 │  ├─ vnc.xml
 │  ├─ vnc.wrapper.log
 │  ├─ vnc.out.log.old
 │  ├─ vnc.out.log
 │  ├─ vnc.err.log.old
 │  ├─ vnc.err.log
 │  ├─ frpc.xml
 │  ├─ frpc.wrapper.log
 │  ├─ frpc.out.log.old
 │  ├─ frpc.out.log
 │  ├─ frpc.err.log.old
 │  └─ frpc.err.log
 └─ WinSW.exe

配置文件内容

frpc.xml 为例

<service>
  <id>frpc</id>
  <name>frpc</name>
  <description>frp自动启动</description>
  <executable>D:\softwares\frp\frpc-a.exe</executable>
  <arguments>-c D:\softwares\frp\frpc.ini</arguments>
  <log mode="roll"></log>
  <startmode>Automatic</startmode>
</service>

安装服务和启动

敲命令

# 安装服务
winsw install ./config/frpc.xml
# 启动
winsw start ./config/frpc.xml

就这样

在找到更好的工具之前,暂时先用这个。

已知问题

我在使用这个工具的时候,经常遇到开机不会自启的问题,即使查看服务管理,确认已经安装的服务是自动启动并且启用的状态,开机后还是不会自启。

不知道是啥问题,我正在寻找这个 WinSW 的代替品。

由于 scoop 是使用 PowerShell 脚本写的,当添加了比较多的 bucket 之后,search 速度会比较慢。

有大佬写了个新的搜索工具,比原版的快多了,使用的语言是我没听过的 Zig 语言。

项目地址: https://github.com/shilangyu/scoop-search

安装方式

scoop install scoop-search

如果想将原来的 search 替换为 scoop-search,可以在 $profile 中添加配置

Invoke-Expression (&scoop-search --hook)

和原版的对比

> scoop search curl
Results from local buckets...

Name    Version Source Binaries
----    ------- ------ --------
curl    8.6.0_2 main
curlie  1.7.2   main
gnupg1  1.4.23  main   gpgkeys_curl.exe
gow     0.8.0   main   curl.exe
grpcurl 1.8.9   main

scoop-search

x scoop-search curl
'main' bucket:
    curl (8.6.0_2)
    curlie (1.7.2)
    gnupg1 (1.4.23) --> includes 'gpgkeys_curl.exe'
    gow (0.8.0) --> includes 'curl.exe'
    grpcurl (1.8.9)

gow

在 Windows 补齐 Unix 工具链

项目地址: https://github.com/bmatzelle/gow

Gow (Gnu On Windows) is the lightweight alternative to Cygwin. It uses a convenient Windows installer that installs about 130 extremely useful open source UNIX applications compiled as native win32 binaries. It is designed to be as small as possible, about 10 MB, as opposed to Cygwin which can run well over 100 MB depending upon options.

里面有一百多个 Unix 系的小工具,比如我常用的 nano

具体的工具列表在这: https://github.com/bmatzelle/gow/wiki/executables_list

安装很简单,使用 scoop

scoop install gow

gsudo

Windows 下的 sudo 工具

在 Linux 下要以管理员权限执行命令只需要在最前面加上 sudo 即可,Windows 却很麻烦,需要专门打开一个管理员模式的 PowerShell 窗口。

这个小工具可以解决这个问题,使用方法和 Linux 的 sudo 命令一样。

PS:好消息是微软打算在 Windows 11 里加入原生的 sudo 命令

安装

scoop install gsudo

proxychains

命令行代理工具

也是 Linux 下常用的,没想到 Windows 也能用,(但似乎有点奇怪的问题)

安装

scoop install proxychains

erdtree

使用 rust 开发的文件树展示工具

写文章的时候用来展示目录结构很方便,没必要目录结构都截图。

安装

scoop install erdtree

我常用的参数

erd -L 3 --dir-order last -y inverted --suppress-size -.

参数说明:

  • -L 3: 遍历3级目录
  • --dir-order last: 目录显示在前面
  • -y inverted: -y 是设置 layout ,可选项为 regular, inverted, flat, iflat
  • --suppress-size: 隐藏文件大小
  • -.: 显示隐藏文件

blessed-contrib

这是一个命令行的仪表盘组件库,基于 Nodejs ,实际作用似乎没有,不过就是好玩,众所周知 Linux 下有很多好玩的命令行工具,但 Windows 这边就少了很多,这个是用 Nodejs 开发的,所以是跨平台的,Windows 也可以用。

项目地址: https://github.com/yaronn/blessed-contrib

使用方法

git clone https://github.com/yaronn/blessed-contrib.git
cd blessed-contrib
npm install
node ./examples/dashboard.js

需要安装 Nodejs 环境,稍微麻烦一点,如果有用 go 或者 rust 开发的类似工具就好了。

加入到 $profile 方便后续使用,打开配置文件

nano $profile

添加一个 PowerShell 函数

function dashboard {
	node "C:\path\to\blessed-contrib\examples\dashboard.js"
}

后续只要输入 dashboard 命令就可以了

posted @ 2024-03-05 09:56  程序设计实验室  阅读(721)  评论(0编辑  收藏  举报