mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-06-08 12:32:06 +08:00
Add auto-update disabling feature to Cursor ID modifier scripts
- Implemented `disable_auto_update()` function for Linux, macOS, and Windows scripts - Added interactive prompt to allow users to disable Cursor's automatic updates - Included comprehensive manual guide for users if automatic disabling fails - Enhanced error handling and validation for update disabling process - Provided clear instructions and fallback methods across different platforms
This commit is contained in:
parent
09a95b999f
commit
2cfd7e63e5
@ -243,6 +243,87 @@ show_follow_info() {
|
||||
echo
|
||||
}
|
||||
|
||||
# 修改 disable_auto_update 函数,在失败处理时添加手动教程
|
||||
disable_auto_update() {
|
||||
echo
|
||||
log_warn "是否要禁用 Cursor 自动更新功能?"
|
||||
echo "0) 否 - 保持默认设置 (按回车键)"
|
||||
echo "1) 是 - 禁用自动更新"
|
||||
read -r choice
|
||||
|
||||
if [ "$choice" = "1" ]; then
|
||||
echo
|
||||
log_info "正在处理自动更新..."
|
||||
local updater_path="$HOME/.config/cursor-updater"
|
||||
|
||||
# 定义手动设置教程
|
||||
show_manual_guide() {
|
||||
echo
|
||||
log_warn "自动设置失败,请尝试手动操作:"
|
||||
echo -e "${YELLOW}手动禁用更新步骤:${NC}"
|
||||
echo "1. 打开终端"
|
||||
echo "2. 复制粘贴以下命令:"
|
||||
echo -e "${BLUE}rm -rf \"$updater_path\" && touch \"$updater_path\" && chmod 444 \"$updater_path\"${NC}"
|
||||
echo
|
||||
echo -e "${YELLOW}如果上述命令提示权限不足,请使用 sudo:${NC}"
|
||||
echo -e "${BLUE}sudo rm -rf \"$updater_path\" && sudo touch \"$updater_path\" && sudo chmod 444 \"$updater_path\"${NC}"
|
||||
echo
|
||||
echo -e "${YELLOW}如果要添加额外保护(推荐),请执行:${NC}"
|
||||
echo -e "${BLUE}sudo chattr +i \"$updater_path\"${NC}"
|
||||
echo
|
||||
echo -e "${YELLOW}验证方法:${NC}"
|
||||
echo "1. 运行命令:ls -l \"$updater_path\""
|
||||
echo "2. 确认文件权限为 r--r--r--"
|
||||
echo "3. 运行命令:lsattr \"$updater_path\""
|
||||
echo "4. 确认有 'i' 属性(如果执行了 chattr 命令)"
|
||||
echo
|
||||
log_warn "完成后请重启 Cursor"
|
||||
}
|
||||
|
||||
if [ -d "$updater_path" ]; then
|
||||
rm -rf "$updater_path" 2>/dev/null || {
|
||||
log_error "删除 cursor-updater 目录失败"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
log_info "成功删除 cursor-updater 目录"
|
||||
fi
|
||||
|
||||
touch "$updater_path" 2>/dev/null || {
|
||||
log_error "创建阻止文件失败"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
|
||||
chmod 444 "$updater_path" 2>/dev/null && \
|
||||
chown "$CURRENT_USER:$CURRENT_USER" "$updater_path" 2>/dev/null || {
|
||||
log_error "设置文件权限失败"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
|
||||
# 尝试设置不可修改属性
|
||||
if command -v chattr &> /dev/null; then
|
||||
chattr +i "$updater_path" 2>/dev/null || {
|
||||
log_warn "chattr 设置失败"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
|
||||
# 验证设置是否成功
|
||||
if [ ! -f "$updater_path" ] || [ -w "$updater_path" ]; then
|
||||
log_error "验证失败:文件权限设置可能未生效"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
|
||||
log_info "成功禁用自动更新"
|
||||
else
|
||||
log_info "保持默认设置,不进行更改"
|
||||
fi
|
||||
}
|
||||
|
||||
# 主函数
|
||||
main() {
|
||||
clear
|
||||
@ -273,7 +354,8 @@ main() {
|
||||
show_follow_info
|
||||
show_file_tree
|
||||
log_info "请重启 Cursor 以应用新的配置"
|
||||
echo
|
||||
|
||||
disable_auto_update
|
||||
}
|
||||
|
||||
# 执行主函数
|
||||
|
@ -246,8 +246,77 @@ main() {
|
||||
show_file_tree
|
||||
show_follow_info
|
||||
log_info "请重启 Cursor 以应用新的配置"
|
||||
echo
|
||||
|
||||
# 询问是否要禁用自动更新
|
||||
disable_auto_update
|
||||
}
|
||||
|
||||
# 执行主函数
|
||||
main
|
||||
|
||||
# 询问是否要禁用自动更新
|
||||
disable_auto_update() {
|
||||
echo
|
||||
log_warn "是否要禁用 Cursor 自动更新功能?"
|
||||
echo "0) 否 - 保持默认设置 (按回车键)"
|
||||
echo "1) 是 - 禁用自动更新"
|
||||
read -r choice
|
||||
|
||||
if [ "$choice" = "1" ]; then
|
||||
echo
|
||||
log_info "正在处理自动更新..."
|
||||
local updater_path="$HOME/Library/Application Support/cursor-updater"
|
||||
|
||||
# 定义手动设置教程
|
||||
show_manual_guide() {
|
||||
echo
|
||||
log_warn "自动设置失败,请尝试手动操作:"
|
||||
echo -e "${YELLOW}手动禁用更新步骤:${NC}"
|
||||
echo "1. 打开终端(Terminal)"
|
||||
echo "2. 复制粘贴以下命令:"
|
||||
echo -e "${BLUE}rm -rf \"$updater_path\" && touch \"$updater_path\" && chmod 444 \"$updater_path\"${NC}"
|
||||
echo
|
||||
echo -e "${YELLOW}如果上述命令提示权限不足,请使用 sudo:${NC}"
|
||||
echo -e "${BLUE}sudo rm -rf \"$updater_path\" && sudo touch \"$updater_path\" && sudo chmod 444 \"$updater_path\"${NC}"
|
||||
echo
|
||||
echo -e "${YELLOW}验证方法:${NC}"
|
||||
echo "1. 运行命令:ls -l \"$updater_path\""
|
||||
echo "2. 确认文件权限为 r--r--r--"
|
||||
echo
|
||||
log_warn "完成后请重启 Cursor"
|
||||
}
|
||||
|
||||
if [ -d "$updater_path" ]; then
|
||||
rm -rf "$updater_path" 2>/dev/null || {
|
||||
log_error "删除 cursor-updater 目录失败"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
log_info "成功删除 cursor-updater 目录"
|
||||
fi
|
||||
|
||||
touch "$updater_path" 2>/dev/null || {
|
||||
log_error "创建阻止文件失败"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
|
||||
chmod 444 "$updater_path" 2>/dev/null && \
|
||||
chown "$CURRENT_USER" "$updater_path" 2>/dev/null || {
|
||||
log_error "设置文件权限失败"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
|
||||
# 验证设置是否成功
|
||||
if [ ! -f "$updater_path" ] || [ -w "$updater_path" ]; then
|
||||
log_error "验证失败:文件权限设置可能未生效"
|
||||
show_manual_guide
|
||||
return 1
|
||||
}
|
||||
|
||||
log_info "成功禁用自动更新"
|
||||
else
|
||||
log_info "保持默认设置,不进行更改"
|
||||
fi
|
||||
}
|
||||
|
@ -306,41 +306,111 @@ Write-Host ""
|
||||
Write-Host "$YELLOW[询问]$NC 是否要禁用 Cursor 自动更新功能?"
|
||||
Write-Host "0) 否 - 保持默认设置 (按回车键)"
|
||||
Write-Host "1) 是 - 禁用自动更新"
|
||||
$choice = Read-Host "请输入选项 (1)"
|
||||
$choice = Read-Host "请输入选项 (0)"
|
||||
|
||||
if ($choice -eq "1") {
|
||||
Write-Host ""
|
||||
Write-Host "$GREEN[信息]$NC 正在处理自动更新..."
|
||||
$updaterPath = "$env:LOCALAPPDATA\cursor-updater"
|
||||
|
||||
if (Test-Path $updaterPath) {
|
||||
# 定义手动设置教程
|
||||
function Show-ManualGuide {
|
||||
Write-Host ""
|
||||
Write-Host "$YELLOW[警告]$NC 自动设置失败,请尝试手动操作:"
|
||||
Write-Host "$YELLOW手动禁用更新步骤:$NC"
|
||||
Write-Host "1. 以管理员身份打开 PowerShell"
|
||||
Write-Host "2. 复制粘贴以下命令:"
|
||||
Write-Host "$BLUE命令1 - 删除现有目录(如果存在):$NC"
|
||||
Write-Host "Remove-Item -Path `"$updaterPath`" -Force -Recurse -ErrorAction SilentlyContinue"
|
||||
Write-Host ""
|
||||
Write-Host "$BLUE命令2 - 创建阻止文件:$NC"
|
||||
Write-Host "New-Item -Path `"$updaterPath`" -ItemType File -Force | Out-Null"
|
||||
Write-Host ""
|
||||
Write-Host "$BLUE命令3 - 设置只读属性:$NC"
|
||||
Write-Host "Set-ItemProperty -Path `"$updaterPath`" -Name IsReadOnly -Value `$true"
|
||||
Write-Host ""
|
||||
Write-Host "$BLUE命令4 - 设置权限(可选):$NC"
|
||||
Write-Host "icacls `"$updaterPath`" /inheritance:r /grant:r `"`$($env:USERNAME):(R)`""
|
||||
Write-Host ""
|
||||
Write-Host "$YELLOW验证方法:$NC"
|
||||
Write-Host "1. 运行命令:Get-ItemProperty `"$updaterPath`""
|
||||
Write-Host "2. 确认 IsReadOnly 属性为 True"
|
||||
Write-Host "3. 运行命令:icacls `"$updaterPath`""
|
||||
Write-Host "4. 确认只有读取权限"
|
||||
Write-Host ""
|
||||
Write-Host "$YELLOW[提示]$NC 完成后请重启 Cursor"
|
||||
}
|
||||
|
||||
try {
|
||||
# 删除现有目录
|
||||
if (Test-Path $updaterPath) {
|
||||
try {
|
||||
Remove-Item -Path $updaterPath -Force -Recurse -ErrorAction Stop
|
||||
Write-Host "$GREEN[信息]$NC 成功删除 cursor-updater 目录"
|
||||
}
|
||||
catch {
|
||||
Write-Host "$RED[错误]$NC 删除 cursor-updater 目录失败"
|
||||
Show-ManualGuide
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
# 创建阻止文件
|
||||
try {
|
||||
# 强制删除目录
|
||||
Remove-Item -Path $updaterPath -Force -Recurse -ErrorAction Stop
|
||||
Write-Host "$GREEN[信息]$NC 成功删除 cursor-updater 目录"
|
||||
|
||||
# 创建同名文件
|
||||
New-Item -Path $updaterPath -ItemType File -Force | Out-Null
|
||||
New-Item -Path $updaterPath -ItemType File -Force -ErrorAction Stop | Out-Null
|
||||
Write-Host "$GREEN[信息]$NC 成功创建阻止文件"
|
||||
}
|
||||
catch {
|
||||
Write-Host "$RED[错误]$NC 处理 cursor-updater 时出错: $_"
|
||||
Write-Host "$RED[错误]$NC 创建阻止文件失败"
|
||||
Show-ManualGuide
|
||||
return
|
||||
}
|
||||
|
||||
# 设置文件权限
|
||||
try {
|
||||
# 设置只读属性
|
||||
Set-ItemProperty -Path $updaterPath -Name IsReadOnly -Value $true -ErrorAction Stop
|
||||
|
||||
# 使用 icacls 设置权限
|
||||
$result = Start-Process "icacls.exe" -ArgumentList "`"$updaterPath`" /inheritance:r /grant:r `"$($env:USERNAME):(R)`"" -Wait -NoNewWindow -PassThru
|
||||
if ($result.ExitCode -ne 0) {
|
||||
throw "icacls 命令失败"
|
||||
}
|
||||
|
||||
Write-Host "$GREEN[信息]$NC 成功设置文件权限"
|
||||
}
|
||||
catch {
|
||||
Write-Host "$RED[错误]$NC 设置文件权限失败"
|
||||
Show-ManualGuide
|
||||
return
|
||||
}
|
||||
|
||||
# 验证设置
|
||||
try {
|
||||
$fileInfo = Get-ItemProperty $updaterPath
|
||||
if (-not $fileInfo.IsReadOnly) {
|
||||
Write-Host "$RED[错误]$NC 验证失败:文件权限设置可能未生效"
|
||||
Show-ManualGuide
|
||||
return
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "$RED[错误]$NC 验证设置失败"
|
||||
Show-ManualGuide
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "$GREEN[信息]$NC 成功禁用自动更新"
|
||||
}
|
||||
else {
|
||||
# 直接创建阻止文件
|
||||
New-Item -Path $updaterPath -ItemType File -Force | Out-Null
|
||||
Write-Host "$GREEN[信息]$NC 成功创建阻止文件"
|
||||
catch {
|
||||
Write-Host "$RED[错误]$NC 发生未知错误: $_"
|
||||
Show-ManualGuide
|
||||
}
|
||||
}
|
||||
elseif ($choice -ne "") {
|
||||
Write-Host "$YELLOW[信息]$NC 保持默认设置,不进行更改"
|
||||
}
|
||||
else {
|
||||
Write-Host "$YELLOW[信息]$NC 保持默认设置,不进行更改"
|
||||
Write-Host "$GREEN[信息]$NC 保持默认设置,不进行更改"
|
||||
}
|
||||
|
||||
|
||||
|
||||
Write-Host ""
|
||||
Read-Host "按回车键退出"
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user