VS Code - 当前活动文件所在文件夹的完整路径

Wel*_*ell 6 visual-studio-code

我想在VS Code中创建任务,但我需要实际文件的路径.这里有一些选择吗?我的任务:

{
    "version": "0.1.0",
    "command": "${workspaceRoot}/run.sh",
    "isShellCommand": true,
    "options": {
        "cwd": "${hereINeedPathToActualFile}"
    },
    "args": ["${file}"],
    "showOutput": "always"
}
Run Code Online (Sandbox Code Playgroud)

非常感谢

man*_*ire 13

window.title 是用户设置中适合我的设置:
"window.title": "${activeEditorMedium}"

其他选择:

  // Controls the window title based on the active editor. Variables are substituted based on the context:
  // ${activeEditorShort}: e.g. myFile.txt
  // ${activeEditorMedium}: e.g. myFolder/myFile.txt
  // ${activeEditorLong}: e.g. /Users/Development/myProject/myFolder/myFile.txt
  // ${rootName}: e.g. myProject
  // ${rootPath}: e.g. /Users/Development/myProject
  // ${appName}: e.g. VS Code
  // ${dirty}: a dirty indicator if the active editor is dirty
  // ${separator}: a conditional separator (" - ") that only shows when surrounded by variables with values
  "window.title": "${activeEditorShort}${separator}${rootName}",
Run Code Online (Sandbox Code Playgroud)


Pei*_* Li 6

前往设置。在 UserSettings 内,将此行添加到 JSON blob:

"window.title": "${activeEditorLong}"


Dan*_*lia 5

如果您需要访问文件,您可以从工作区根目录获取其位置:

"filelocation": "${workspaceRoot}/.vscode/tasks.json",

// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
Run Code Online (Sandbox Code Playgroud)


Leo*_*Leo 5

这个问题几个月前就已经得到解决:

在 UI 中显示完整的工作空间路径 #3119

有一个新设置window.showFullPath,启用后将显示当前打开文件的完整路径,而不是工作区相对路径。

该功能计划在 11 月版本中发布,目前正在测试中。window.showFullPath然后你可以在配置文件中控制它。


更新:

自从我发布原始答案以来,设置已更改。它现在称为window.title,您可以自定义任何您喜欢的内容。