重置 Git 提交的作者信息

历史提交用了错误的用户名和邮件(比如受组织要求),想要修改成正确的。并且尽量保持信息不变。

# 添加参数来修改为正确的用户信息
git config user.name
git config user.email 
# 修改最后一个提交的用户信息,但是根据文档所说,会重置提交时间
git commit --amend --reset-author
# 但是手动指定就不会重置时间
git commit --amend --author 'My Name <email@example.com>'

同 WSL 分享 SSH Agent


设备上安装了 WSL2,配置有带 MinGW-64 Git for Windows,还使用 Putty 的 WinSCP。那少不了各端同步、分享 SSH 私钥。最好是有一处统一管理私钥,并且提供 SSH_AUTH_SOCK 给程序使用。

考虑跨平台的话 1Password 是个挺好的选项,但未来我不一定还继续订阅。所以在 macOS 上我使用 maxgoedjen/secretive: Store SSH keys in the Secure Enclave 管理,在 Windows 考虑用 Microsoft OpenSSH

对于 Windows 自带的 OpenSSH Client,它有两个版本 😩,别装多了,受其他依赖要求,这里选择 GitHub 版本。

  1. Key-Based Authentication in OpenSSH for Windows | Microsoft Learn 可以在 Windows 可选功能中添加,在我的 24H2 上当前是 OpenSSH_for_Windows_9.5p2, LibreSSL 3.8.2 版本
  2. PowerShell/Win32-OpenSSH: Win32 port of OpenSSH 仓库提供最新的版本,但安装在非系统目录,使用 winget install Microsoft.OpenSSH.Preview 一键安装。
    当前最新版是 OpenSSH_for_Windows_9.8p2 Win32-OpenSSH-GitHub, LibreSSL 4.0.0
    注意,卸载它时居然会导致 Microsoft OpenSSH Agent 服务被删除,也是奇了怪了。得重新添加一遍系统可选功能。
    令人惊喜的是,重启并不会清空 ssh-agent 服务的记忆,就像 Key-Based Authentication in OpenSSH for Windows | Microsoft Learn 说的一样,直到 ssh-add -D 手动移除。这玩意是不是安全我不好说,但我正需要一个类似 Apple KeyChain 那种通过 ssh-add --apple-use-keychain 加进去就不用管密码的管理器(非订阅制的 1Password),反倒喜欢这种加入私钥后可以删除原文件的行为(虽然实际内容转移到大型数据库——注册表上了)。也有人不喜欢这种行为 ssh-agent: permanent loaded ssh-key storage · 议题 #1487 · PowerShell/Win32-OpenSSH

对于 Putty 系的 pageant,使用 winget install winssh-pageant 安装了 ndbeals/winssh-pageant: Bridge to Windows OpenSSH agent from Pageant. This means the openssh agent has the keys and this proxies pageant requests to it. 来打通二者。注意它需要 GitHub 版本的 OpenSSH for Windows。

WSL 里也有一份 SSH,当执行 ssh 用的是 /usr/bin/ssh,而 ssh.exe 才是 Windows 版的。

想要让 WSL2 也连接到 Windows OpenSSH Agent,需要一套 socat + npiperelay 胶起来

/etc/profile.d/wsl-ssh-agent.sh
#!/usr/bin/env sh
# Expose Windows SSH-Agent inside WSL environments 
# source: https://github.com/microsoft/WSL/issues/11207#issuecomment-2921237689 
 
export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR%/}/ssh-agent.sock"
 
# Exit if socket already exists and is a valid socket
if ss -lxn | grep -q "$SSH_AUTH_SOCK"; then
  return
fi
 
# Remove the stale socket, if it exists
rm -f "$SSH_AUTH_SOCK"
 
# Launch socat/npiperelay as a background process
( setsid socat \
  UNIX-LISTEN:"$SSH_AUTH_SOCK",fork \
  EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork \
  & ) >/dev/null 2>&1

Synology 上的 htop 没颜色

很早就注意到了,Synology DSM 7.1 系统上执行 htop 不能展示颜色,所以一直用的 Monochromatic 色彩模式。今天打算纠正这个错误。
查查有人建议换个 TERM 变量,确实换到 TERM=xterm 或者 TERM=xterm-color 都是有颜色的,当然二者有些许区别。
在多个系统间对比 /usr/share/terminfo/x/xterm-256color 文件的 MD5,完全不一样。虽然如此,从另一台设备复制一个粘贴过去,就有颜色了。

终端色彩输出测试工具

在探索 Synology 上的 htop 没颜色 的过程中,点进了 bash - Why is htop not displaying colors only for my local machine? - Super User 这个问题,里面的终端色彩测试图吸引到我了。
msgcat --color=test就是个简单的 msgcat --color=test 命令,并且这个工具是 GNU gettext 工具附带的,整个指令参数在 GNU gettext utilities 文档里只是提了一嘴,像是个彩蛋。

可问题是我怎么都没能让这个工具在 Debian 13 上运行起来,版本是 0.21,而 MSYS2 UCRT64 上是 0.24 可以运行起来。

看源码怎么都想不通,放 IDA 里一看原来是相关分支压根没编译进来。在 ldd 输出里没有包含 libtextstyle 库,也就是编译 GNU libtextstyleHAVE_LIBTEXTSTYLE=no,导致 bool handle_color_option (const char *option) 这个函数,编译时被 inline 为 false 了。

另外,Windows 平台还没有找到能像上图一样显示出完整渐变色的终端模拟器。

ShellCheck 吃满内存

在探索 终端色彩输出测试工具 过程中,使用 VSCode 浏览 gettext 源码时,全局搜索某个词汇,很多搜索结果落在 ./configure 这个自动生成的大号 shell 脚本文件中。如果设置了 "shellcheck.run": "onType"(默认值也是这个),会启动很多个 shellcheck 进程不断吃内存。解析的量太大了,我也怀疑有死循环。

稍微找到了缓解方式,不好加在单个文件上,就为工作区全局设置了

"shellcheck.customArgs": [
  "--extended-analysis=false"
]