)
文章目录在 VS Code 中让终端显示简洁路径告别冗长全路径问题场景快速解决方案1. 修改终端标签页标题2. 按 Shell 类型优化提示符 **PowerShellWindows** **BashLinux/macOS/WSL** **ZshmacOS 默认**3. 解决常见问题❌ 设置不生效 进阶技巧完整配置示例总结对比在 VS Code 中让终端显示简洁路径告别冗长全路径问题场景你是否厌倦了 VS Code 终端显示长长的完整路径占满标签栏空间比如C:\Users\YourName\Documents\Projects\my-project\src\components\utils而实际上你只关心最后的目录名。快速解决方案1. 修改终端标签页标题在 VS Code 的settings.json中添加{ terminal.integrated.tabs.title: ${cwdFolder}, terminal.integrated.tabs.description: ${cwd} }效果标签页显示utils仅最后一级鼠标悬停显示完整路径可选变量${process}- 显示终端进程名bash/powershell${cwdFolder}- 仅当前目录名推荐${cwd}- 完整路径默认2. 按 Shell 类型优化提示符PowerShellWindows修改$PROFILE文件# 1. 打开配置文件 notepad $PROFILE # 如果文件不存在先创建 New-Item -Path $PROFILE -Type File -Force # 2. 添加简洁提示符 function prompt { $folder Split-Path -Leaf -Path (Get-Location) PS $folder }高级版带颜色和 Git 分支function prompt { $currentFolder Split-Path -Leaf -Path (Get-Location) Write-Host PS $currentFolder -NoNewline -ForegroundColor Green Write-VcsStatus Write-Host -NoNewline return }BashLinux/macOS/WSL编辑~/.bashrcexport PS1\u\h:\W\$ # \W 表示当前目录名ZshmacOS 默认编辑~/.zshrcPROMPT%1~ $ # %1~ 表示最后一级目录3. 解决常见问题❌ 设置不生效关闭旧终端新建终端 - 修改设置后需要新建终端标签页检查 Shell 配置文件 - 确保 Shell 没有用转义序列覆盖标题验证 VS Code 加载了 Profile{ terminal.integrated.shellArgs.windows: [] # 确保没有 -NoProfile } 进阶技巧在settings.json中添加分隔符terminal.integrated.tabs.separator: - 效果bash - src使用${sequence}让 Shell 完全控制标题terminal.integrated.tabs.title: ${sequence}完整配置示例VS Code settings.json{ terminal.integrated.tabs.title: ${cwdFolder}, terminal.integrated.tabs.description: ${cwd}, terminal.integrated.tabs.separator: - , terminal.integrated.shellArgs.windows: [], terminal.integrated.fontSize: 14 }PowerShell Profile# 显示简洁路径 Git 状态 function prompt { $currentFolder Split-Path -Leaf -Path (Get-Location) Write-Host [ -NoNewline -ForegroundColor DarkGray Write-Host $currentFolder -NoNewline -ForegroundColor Cyan Write-Host ] -NoNewline -ForegroundColor DarkGray if (Get-Command git -ErrorAction SilentlyContinue) { $branch git branch 2$null | Select-String ^\* | ForEach-Object { $_.ToString().Split()[1] } if ($branch) { Write-Host ( -NoNewline -ForegroundColor DarkGray Write-Host $branch -NoNewline -ForegroundColor Yellow Write-Host ) -NoNewline -ForegroundColor DarkGray } } Write-Host -NoNewline -ForegroundColor Green return }总结对比配置前配置后优点C:\Users\...\my-project\srcsrc节省标签栏空间usernamehost:/long/path/to/project$project$提示符更简洁鼠标悬停无额外信息悬停显示完整路径两全其美一句话总结修改terminal.integrated.tabs.title 自定义 Shell 提示符让你的 VS Code 终端既简洁又实用。试试这些设置让你的开发环境更加优雅高效有任何问题欢迎留言讨论。