从命令行列出 VS Code 最近的工作区

List VS Code recent workspaces from the command line

打开一个新的 VS Code 实例,然后按 ctrl+R 显示最近打开的几乎所有工作区的列表。

如何从命令行获取此列表?

它们存储在 json 或文本文件中吗?

在 Windows 10 系统上,以下 powershell 脚本 returns 每个保存的 VS 代码工作区文件的路径按上次访问的顺序排序。相应地更改 $WorkSpacesPath 路径变量。

编辑 以反映最近对 vscode 核心的更改以及它如何保存对工作区文件的引用。可能是更好的方法,但这就足够了。

$WorkSpacesPath = "C:\Users\UserName\AppData\Roaming\Code\User\workspaceStorage"

$ws =  (
    Get-Item -Path $WorkSpacesPath\*\*.json | `
    Foreach-Object  { 
        (Get-Content ($_.FullName) | ConvertFrom-Json).configuration `
        -Replace 'file:///|[\s]+', '' `
        -Replace '/', '\' `
        -Replace '%3a', ':' `
        -Replace '%20', ' ' `
        }
    )

## BEGIN EDIT
$ws +=  (
    (Get-Item -Path $CodeWorkSpaces\*\*.json | `
    Foreach-Object  { 
        (Get-Content ($_.FullName) | ConvertFrom-Json).configuration.fsPath `
        }
    ) | `
    Where-Object { $_ } | `
    Get-Unique -AsString | `
    Foreach-Object {
        Get-Item -Path $_ -EA SilentlyContinue | `
        Select-Object -Property BaseName, FullName, LastAccessTime  `
    } | `
    Sort-Object -Property LastAccessTime `
) 
## END EDIT

 $ws | `
    Where-Object { $_ } | `
    Get-Unique -AsString | `
    Foreach-Object {
        Get-Item -Path $_ -EA SilentlyContinue | `
        Select-Object -Property BaseName, FullName, LastAccessTime  `
    } | `
    Sort-Object -Property LastAccessTime 

$idx = 0
$ws | Foreach-Object {$_ | Add-Member @{Index = $idx } -Force; $idx++ } 

$ws | Select-Object -Property Index, BaseName, LastAccessTime, FullName