2017-04-24 62 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

相關問題