分类 各种DIY 下的文章

背景

在VSCode中使用Roo Code时,遇到终端集成问题,Roo Code无法在终端中执行各种操作,也无法获取输出,非常不方便。

解决步骤

1、检查powershell版本。
按下 Win + R,输入 pwsh,如果报找不到文件pswh,则版本不对,需要升级。
2、在powershell命令行中输入以下命令,安装新版本。

winget search Microsoft.PowerShell
winget install --id Microsoft.PowerShell --source winget

3、用pswh方式打开新的powershell,执行以下命令。

New-Item -Path $PROFILE -ItemType File -Force

在创建的文件中写入以下内容:

if ($env:TERM_PROGRAM -eq "vscode") {
  . "$(code --locate-shell-integration-path pwsh)"
}

4、以管理员方式启动powershell,执行以下命令。

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

5、在VSCode中按下Ctrl + Shift + P,输入Preferences: Open User Settings (JSON),填入以下内容。

    "terminal.integrated.defaultProfile.windows": "PowerShell 7",
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ]
        },
        "PowerShell 7": {
            "path": "你的pwsh.exe路径",
            "args": []
        }
    },

6、在VScode终端中输入以下命令:

$PSVersionTable.PSVersion

看是否有正确输出。

参考资料

https://zhuanlan.zhihu.com/p/25724740375

背景

每次AirPods连接MAC都会被音量吓一跳。

步骤

1、安装Hammerspoon。

brew install hammerspoon --cask

2、创建默认配置。

mkdir -p ~/.hammerspoon
touch ~/.hammerspoon/init.lua

3、在init.lua中写入配置

-- 存储上一次默认音频输出设备的名称
local lastOutputDeviceName = hs.audiodevice.defaultOutputDevice():name()

-- 处理设备变更的回调函数
local function handleDeviceChanges()
-- 获取当前默认音频输出设备的名称
local currentOutputDeviceName = hs.audiodevice.defaultOutputDevice():name()
-- 判断设备名称是否发生了变化
if lastOutputDeviceName ~= currentOutputDeviceName then
-- 判断当前设备是否为蓝牙耳机
if string.find(currentOutputDeviceName, "AirPods") then
-- 连接蓝牙耳机时将音量设置为 20
hs.audiodevice.defaultOutputDevice():setVolume(20)
hs.alert.show("音量已设为 20")
-- 判断上一个设备是否为蓝牙耳机
elseif string.find(lastOutputDeviceName, "AirPods") then
-- 断开蓝牙耳机时将音量设置为 0
hs.audiodevice.defaultOutputDevice():setVolume(0)
hs.alert.show("音量已设为 0")
end
end
-- 更新 lastOutputDeviceName 为当前设备名称
lastOutputDeviceName = currentOutputDeviceName
end

-- 为音频设备变动设置回调函数
hs.audiodevice.watcher.setCallback(handleDeviceChanges)
-- 启动音频设备监听器
hs.audiodevice.watcher.start()

4、重新加载配置。
在启动台搜索Hammerspoon,启动应用。然后在标题栏点击他的图标,然后选择Reload Config。

参考资料

https://www.v2ex.com/t/1011644

1 字体下载

wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf &&
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf  &&
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf  &&
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf

分别下载以上字体,并双击安装

2 在vscode中设置字体

在设置中搜索font,然后找到Features-Terminal,将其中的Font-Family设置为MesloLGS NF,重启VSCode即可。

3 其他远程连接软件

同样将字体设置为MesloLGS NF,重启即可。

4 好用插件

默认提供以下功能:
z 关键词:快速跳转到含有上面关键词的路径中
命令自动补全:输入关键词,然后按方向右键,自动补全之前执行过的命令。

1、安装 libpam-google-authenticator

sudo apt update
sudo apt install libpam-google-authenticator -y

2、为每个用户生成 TOTP 密钥

google-authenticator

3、回答显示的问题,默认y就可以。
4、使用微软或者谷歌验证器扫码。
5、拍照记录应急验证码。
6、配置 PAM 模块启用 TOTP

sudo nano /etc/pam.d/sshd

在文件最上方添加以下内容:

auth required pam_google_authenticator.so nullok

如果必须使用两步验证,则:

auth required pam_google_authenticator.so

7、编辑ssh配置。

sudo nano /etc/ssh/sshd_config

修改以下内容:

ChallengeResponseAuthentication yes
UsePAM yes
PasswordAuthentication yes  # 如使用公钥登录可为 no
KbdInteractiveAuthentication yes  # 这一行必不可少,否则不能使用xshell,termius等

8、重启ssh服务,使上述配置生效。

sudo systemctl restart ssh

背景

screen是常用的会话管理工具,然而已经过时,在RHEL中甚至不再提供。tmux是更现代化的会话管理工具,因此决定从screen迁往tmux。下面记录基本的常用操作。

常用操作

1、新建会话

tmux new -s session_name

2、开始记录日志

script -f file_name

3、断开会话

先按ctrl+b,然后再按d

4、返回会话

tmux attach -t session_name

5、查看已经存在的会话

tmux ls

6、向上翻阅日志

先按ctrl+b,然后按[

7、取消翻阅日志

按下ESC键或者q键

8、tmux前缀

ctrl+b

9、上下切分窗格

先按前缀键,然后再按引号

10、左右切分窗格

先按前缀键,再按百分号键

11、退出窗格

先按前缀键,然后x
或者直接ctrl+D

12、退出窗口

先按前缀键,然后再按&
或者直接ctrl+D