2016-04-20 36 views
3

我想在VS代碼中創建任務,但我需要指向實際文件的路徑。這裏有一些選擇嗎? 我的任務:VS代碼 - 當前活動文件所在文件夾的完整路徑

{ 
    "version": "0.1.0", 
    "command": "${workspaceRoot}/run.sh", 
    "isShellCommand": true, 
    "options": { 
     "cwd": "${hereINeedPathToActualFile}" 
    }, 
    "args": ["${file}"], 
    "showOutput": "always" 
} 

非常感謝

回答

4

如果您需要訪問一個文件,你可以從工作區根派生它的位置:

"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 
+0

嗨,我需要變量「cwd」 – Well

1

這個問題已經在幾個月前處理:

https://github.com/Microsoft/vscode/issues/3119

有一個新的設置window.showFullPath一旦啓用將顯示當前打開的文件的完整路徑,而不是工作區相對路徑。

該功能計劃於11月發佈,目前正在測試中。然後你可以在配置文件中用window.showFullPath來控制它。


UPDATE:

,因爲我張貼的答案原來的設置已被更改。它現在叫做window.title,你可以自定義你喜歡的任何東西。

+0

這不適用於我在我的Macbook上我寫了「window.showFullPath」:是的,它抱怨這是一個未知的設置。 –

+0

@PeitiPeterLi我在半年前發佈了這個答案。從那時起,設置已經改變。它現在被稱爲** window.title **,您可以自定義您喜歡的任何內容。 – Leo

3

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}", 
2

去設置,裏面UserSettings這行添加到JSON BLOB:

「window.title」:「$ {activeEditorLong}」

相關問題