2024, Practical Enhancements for Windows Development and Usage Experience - Terminal & Command Line Edition
Hmph, is Windows Terminal a disaster zone? Using scoop to install software, Starship for beautification, but WinSW auto-start is still trash. Tsk, another scoop-search replacing the original, gow to complement Unix tools, gsudo to simulate sudo, but proxychains seems a bit odd. Oh, blessed-contrib dashboard? Just for fun, better to use erdtree to view directories.
目录25 个章节
Preface
Building on earlier groundwork, I'm finally continuing the updates here. This will most likely be the last installment in this series for now.
Additionally, I've incorporated some previous content updates into this piece as well.
Supplementary Notes on the Scoop Package Manager
This section provides additional information and tips for managing software using the Scoop command-line installer for Windows.
Common Scoop Commands
scoop help # View help
scoop help <some command> # View help for a specific command
scoop info <app> # View APP information
scoop install <app> # Install APP
scoop uinstall <app> # Uninstall APP
scoop reset [app]@[version] # Switch versions
scoop list # List installed apps
scoop search # Search for apps
scoop status # Check which apps have updates
scoop update # Update Scoop itself
scoop update appName1 appName2 # Update certain apps
scoop update * # Update all apps (requires operating within the apps directory)
scoop bucket known # Use this command to list all known buckets (software sources)
scoop bucket add bucketName # Add a specific bucket
scoop cache rm <app> # Remove the cache for a specific app
scoop cache rm * # Remove all caches
scoop cleanup <app> # Delete old versions
scoop Frequently Asked Questions
Hash check errors when installing software
- If the error persists after multiple installation attempts, locate its JSON file, download it locally, modify its hash value, and upload it to your own bucket, then update it.
- Use the
scoop install -soption to ignore the hash check. For specific usage, refer toscoop help install
How to remove old versions of software when updating
Use the scoop cleanup command. For specific usage, see scoop help cleanup
Terminal
OK, we've arrived at a major pain point in the Windows development experience.
The command line has always been a weakness of Windows, but with some Rust toolchains (Rust 工具链), this situation can be gradually improved.
Nerd Fonts
To beautify your terminal interface, start by installing a Nerd Font.
This is where a package manager comes in handy again—you can install it using Scoop.
First, add the bucket:
scoop bucket add nerd-fonts
Project URL: https://github.com/matthewjberger/scoop-nerd-fonts
Then, choose a font you like and install it:
scoop install FiraCode-NF
Additionally, this bucket contains many fonts and is no longer limited to Nerd Fonts. You can also install some regular fonts, for example:
scoop install SarasaGothic-SC # Install Sarasa Gothic (Simplified Chinese)
scoop install Wenquanyi-Microhei # Install WenQuanYi Micro Hei
scoop install Wenquanyi-Zenhei # Install WenQuanYi Zen Hei
References
Built-in PowerShell
To get straight to the point: the built-in PowerShell is garbage.
I do not recommend using oh-my-posh, as its startup speed is too slow. PowerShell's startup is already slow, and adding oh-my-posh makes it even slower.
For terminal customization, just use Starship. I will introduce it later.
How to edit the configuration: nano $PROFILE
Here is my configuration:
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 the Starship prompt in PowerShell Set the environment variable for Starship configuration
Invoke-Expression (&starship init powershell)
$ENV:STARSHIP_CONFIG = "$HOME\.config\starship\plain-text-symbols.toml"
PowerShell 7
This is Microsoft's new open-source, cross-platform terminal, which is a bit more powerful and performant than the built-in PowerShell. (Judging from the project repository, it's developed using C#, which helps with good cross-platform support.)
Project Address: https://github.com/PowerShell/PowerShell
Just download an installer and you're good to go.
My $PROFILE configuration
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
- Configuration - https://starship.rs/zh-CN/config/
- Presets - https://starship.rs/zh-CN/presets/
### NuShell
https://www.nushell.sh/zh-CN/book/
### References
- Unifying the styles of cmd, PowerShell, Git Bash, etc., with Starship - https://zhuanlan.zhihu.com/p/674148271
- Step-by-step guide to building a modern unified terminal (Alacritty + Zellij -> WezTerm) - https://zhuanlan.zhihu.com/p/436024560
## Command Line Tools
### WinSW
A process management tool, similar to `supervisor` in Linux, which can install programs to run as services and set them to run automatically.
#### Installation
```bash
scoop install winsw
Usage
Similar to supervisor, write a configuration file, then install the service, which can be started, stopped, etc.
My Directory Structure
Here, I have set up two services: vnc and 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
Configuration File Content
Taking frpc.xml as an example.
<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>
Install the Service and Start
Type the command.
# Install Service
winsw install ./config/frpc.xml
# Start
winsw start ./config/frpc.xml
That's it.
For now, use this until a better tool is found.
Known Issues
I frequently encounter the issue of this tool failing to start automatically on boot. Even when I check the Service Manager and confirm that the installed service is set to Automatic and enabled, it still does not start upon startup.
I'm not sure what the problem is, and I'm currently looking for an alternative to WinSW.
scoop-search
Since scoop is written using PowerShell scripts, the search speed becomes relatively slow after adding many buckets.
An expert wrote a new search tool that is much faster than the original, using the Zig language, which I hadn't heard of before.
Project URL: https://github.com/shilangyu/scoop-search
Installation Method
scoop install scoop-search
If you want to replace the original search with scoop-search, you can add the following configuration to $profile.
Invoke-Expression (&scoop-search --hook)
Comparison with the original version
> 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
Completing the Unix Toolchain on Windows
Project URL: 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.
It contains over a hundred Unix-like utilities, for example, the nano editor I often use.
The specific tool list is available here: https://github.com/bmatzelle/gow/wiki/executables_list
Installation is simple, using Scoop:
scoop install gow
gsudo
A sudo tool for Windows
In Linux, to execute a command with administrator privileges, you simply prepend sudo. This is quite cumbersome on Windows, as it requires opening a dedicated PowerShell window in administrator mode.
This small tool solves this problem. Its usage is identical to the sudo command in Linux.
PS: Good news is that Microsoft plans to add a native
sudocommand in Windows 11.
Installation
scoop install gsudo
proxychains
Command-line proxy tool
Commonly used in Linux, and surprisingly also works on Windows, (but seems to have some strange issues)
Installation
scoop install proxychains
erdtree
A file tree display tool developed in Rust
Convenient for showing directory structure when writing articles—no need to screenshot the directory structure.
Installation
scoop install erdtree
Common parameters I use
erd -L 3 --dir-order last -y inverted --suppress-size -.
Parameter descriptions:
-L 3: Traverse 3 levels of directories--dir-order last: Display directories first-y inverted:-ysets the layout; options includeregular,inverted,flat, andiflat--suppress-size: Hide file sizes-.: Show hidden files
blessed-contrib
This is a command-line dashboard component library built on Nodejs. While it may not have much practical use, it's fun to play with. As we all know, Linux has many interesting command-line tools, but Windows has fewer. Since this is developed with Nodejs, it's cross-platform and can also be used on Windows.
Project URL: https://github.com/yaronn/blessed-contrib
Usage
git clone https://github.com/yaronn/blessed-contrib.git
cd blessed-contrib
npm install
node ./examples/dashboard.js
Requires a Nodejs environment to be installed, which is slightly more cumbersome. It would be great if there were similar tools developed in Go or Rust.
Add to $profile for convenient future use. Open the configuration file.
nano $profile
Add a PowerShell function.
function dashboard {
node "C:\path\to\blessed-contrib\examples\dashboard.js"
}
Subsequently, you can simply type the dashboard command.
_EOF_
2024, Practical Enhancements for Windows Development and Usage Experience - Terminal & Command Line Edition
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
IT之家学院:让你的Win10桌面比macOS还简洁漂亮高大上
感谢IT之家网友 yiyueduzui 的原创投稿 直奔主题,先给大家看看我的电脑桌面: 有人开始骂了:你特么逗我呢?这明明就是一张图片好不啦! 我读书那么多,怎么会骗你,这真的是我的电脑桌面,不还有个桌面数字时钟呢嘛!论简洁,还有谁? 那这啥都没有,要怎么用啊? 看好啦,当我的鼠标移动到屏幕下方的时候, 出现了一个Dock栏,跟苹果系统的一样一样的。 有些图标其实是一个目录或者文件夹,当它展开的
2021-12-18 · Windows · 约 1 分钟
Windows设置Pageant开机自动启动并且加载秘钥
场景 用Linux的时候ssh和git这些很方便,因为只要一次ssh-add就可以一劳永逸,以后需要认证的时候ssh-agent会帮我们搞定,不需要输入秘钥的密码。 其实Windows也可以实现这种生产力解放,就是用putty附带的工具里的Pageant。 Pageant主要负责和服务器端进行身份验证,但是每次在启动Pageant后都需要手动的加载秘钥文件,本文就是要介绍让Pageant开机自动加
2021-12-18 · Windows · 约 1 分钟
在 Windows11 上启用 ssh-agent
微软的坑真多!!!
2026-08-25 · Windows · 约 1 分钟
Win10安装Ubuntu子系统教程
一、启用“适用于Linux的Windows子系统” 通过Win10任务栏中的Cortana搜索框搜索打开“启用或关闭Windows功能”,向下滚动列表,即可看到“适用于Linux的Windows子系统”项。 勾选它,确定,然后按提示重启系统。 二、启用开发人员模式 然后进入“设置 - 更新和安全 - 针对开发人员”设置页面,选中“开发人员模式”。如图: 然后就会下载安装开发人员模式程序包,等待安装
2021-12-18 · Windows · 约 1 分钟
讨论
共 0 条加载评论中…