2017-04-24 73 views
3

在终端窗格中,我想通过环境变量或PowerShell变量(首选)引用活动编辑器选项卡的文件或文件夹。事情是这样的:VS Code终端中是否有当前文件或文件夹的变量?

ii $vsActivePath

ii $vsActiveFile

这可能吗?

+1

你所讲的是使用'$ pseditor'这是在综合终端提供了PS扩展的变量。现在没有太多可用的,[相关的SO相同的主题问题](https://stackoverflow.com/questions/44265842/visual-studio-code-psise-equivalent)。 –

+1

您链接的SO问题引导我到[PowerShellEditorServices](http://brandonpadgett.com/powershell/Getting-Started-With-Editor-Commands/)。由于目前还没有模块形式,因此需要做一些工作,但这是有希望的。 – wtjones

回答

2

不知道这是你在寻找什么,但你可以访问各种变量在VS代码,如:

${workspaceRoot} the path of the folder opened in VS Code 
${workspaceRootFolderName} the name of the folder opened in VS Code without any slashes (/) 
${file} the current opened file 

Full details can be found here

+2

如何访问终端中的? – wtjones

0

他们增加了一些新的变量,它包含${fileDirname},这是目前${file}所在目录的路径。 这里的文档似乎有点误导。

这些都是当前可用的选项:

${workspaceFolder} - the path of the folder opened in VS Code 
${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/) 
${file} - the current opened file 
${relativeFile} - the current opened file relative to workspaceFolder 
${fileBasename} - the current opened file's basename 
${fileBasenameNoExtension} - the current opened file's basename with no file extension 
${fileDirname} - the current opened file's dirname 
${fileExtname} - the current opened file's extension 
${cwd} - the task runner's current working directory on startup 
${lineNumber} - the current selected line number in the active file 
+1

这些用于在conf文件中进行变量替换,但它们似乎在终端中不可用。 – wtjones

相关问题