diff --git a/cpp/vscode/install.ps1 b/cpp/vscode/install.ps1 new file mode 100644 index 0000000..fe42fc9 --- /dev/null +++ b/cpp/vscode/install.ps1 @@ -0,0 +1,68 @@ +# 确定文件源 +$sourceFiles = @("keybindings.json", "settings.json") + +# 获取当前用户目录 +$userProfile = [System.Environment]::GetFolderPath("UserProfile") + +# 确定目标路径 +switch ($env:OS) { + "Windows_NT" { + $targetPath = Join-Path -Path $userProfile -ChildPath "AppData\Roaming\Code\User" + } + "Unix" { + if (Test-Path "$userProfile/.config/Code/User") { + $targetPath = Join-Path -Path $userProfile -ChildPath ".config/Code/User" + } else { + Write-Host "目标目录 $userProfile/.config/Code/User 不存在" + exit + } + } + "Darwin" { + $targetPath = Join-Path -Path $userProfile -ChildPath "Library/Application Support/Code/User" + } + default { + Write-Host "不支持的操作系统" + exit + } +} + +# 确保目标路径存在 +if (-not (Test-Path -Path $targetPath)) { + Write-Host "目标路径 $targetPath 不存在" + exit +} + +# 获取当前日期,不包括年份 +$dateString = (Get-Date).ToString("MMddHHmmss") + +# 遍历源文件并复制 +foreach ($file in $sourceFiles) { + $sourceFilePath = Join-Path -Path $PSScriptRoot -ChildPath $file + $destinationFilePath = Join-Path -Path $targetPath -ChildPath $file + + # 打印源路径和目标路径 + Write-Host "源文件路径: $sourceFilePath" + Write-Host "目标文件路径: $destinationFilePath" + Write-Host "" + + if (Test-Path -Path $sourceFilePath) { + if (Test-Path -Path $destinationFilePath) { + # 如果目标路径下文件存在,重命名现有文件 + $fileBaseName = [System.IO.Path]::GetFileNameWithoutExtension($destinationFilePath) + Write-Host "fileBaseName: $fileBaseName" + $fileExtension = [System.IO.Path]::GetExtension($destinationFilePath) + Write-Host "fileExtension: $fileExtension" + $newFileName = "${fileBaseName}_${dateString}${fileExtension}" + Write-Host "newFileName: $newFileName" + $newFilePath = Join-Path -Path $targetPath -ChildPath $newFileName + Rename-Item -Path $destinationFilePath -NewName $newFilePath + Write-Host "已重命名原文件为: $newFilePath" + } + + # 复制新文件 + Copy-Item -Path $sourceFilePath -Destination $destinationFilePath -Force + Write-Host "已复制 $file 到 $targetPath" + } else { + Write-Host "源文件 $sourceFilePath 不存在" + } +} diff --git a/cpp/vscode/keybindings.json b/cpp/vscode/keybindings.json new file mode 100644 index 0000000..796974a --- /dev/null +++ b/cpp/vscode/keybindings.json @@ -0,0 +1,12 @@ +[ + { + "command": "cmake.debugTarget", + "key": "F5", + "when": "cmake:enableFullFeatureSet && inCMakeProject && !cmake:hideDebugCommand && !inDebugMode" + }, + { + "command": "editor.action.revealDefinition", + "key": "ALT+G", + "when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor" + } +] \ No newline at end of file diff --git a/cpp/vscode/settings.json b/cpp/vscode/settings.json new file mode 100644 index 0000000..21f6d62 --- /dev/null +++ b/cpp/vscode/settings.json @@ -0,0 +1,43 @@ +{ + "cmake.showOptionsMovedNotification": false, + "cmake.pinnedCommands": [ + "workbench.action.tasks.configureTaskRunner", + "workbench.action.tasks.runTask" + ], + "editor.lineNumbers": "relative", + "vim.leader": "", + "vim.useSystemClipboard": true, + "vim.useCtrlKeys": true, + "vim.normalModeKeyBindings": [ + { + "before": [ + "", + "g", + "c" + ], + "commands": ["workbench.action.showCommands"], + }, + { + "before": [ + "", + "c", + "f" + ], + "commands": ["editor.action.formatDocument"] + }, + { + "before": [ + "", + "j", + ], + "commands": ["workbench.action.togglePanel"] + }, + { + "before": [ + "g", + "d" + ], + "commands": ["editor.action.revealDefinition"] + } + ] +} \ No newline at end of file