Reputation: 121
I want to create a task in Visual Studio Code, but I need a path to the actual file. Is there some option?
My task:
{
"version": "0.1.0",
"command": "${workspaceRoot}/run.sh",
"isShellCommand": true,
"options": {
"cwd": "${hereINeedPathToActualFile}"
},
"args": ["${file}"],
"showOutput": "always"
}
Upvotes: 12
Views: 26769
Reputation: 61
I used the following in my "launch.json" file to set the current working directory (cwd) prior to launching a Python program:
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"stopOnEntry": false,
"console": "integratedTerminal"
},
So the path to the actual file's directory is in ${fileDirname}.
I don't use ${workspaceRoot}, because it's deprecated and it is the path to the root of the work space, not the current working directory if the current working directory is a folder other than the root.
There is a list of all of the Visual Studio Code Task variables in Variables Reference.
Upvotes: 4
Reputation: 5212
Go to Settings. Inside UserSettings, add this line to the JSON blob:
"window.title": "${activeEditorLong}"
Upvotes: 6
Reputation: 13828
This issue has been addressed several months ago:
Display the full workspace path in UI #3119
There is a new setting
window.showFullPath
that once enabled will show the full path to the currently opened file instead of the workspace relative path.
The feature is planned to ship in the November release, currently in testing. Then you could control it with window.showFullPath
in your configuration file.
UPDATE:
The setting has been changed since I posted the original answer. It's now called window.title, which you could customize whatever you like.
Upvotes: 5
Reputation: 5367
If you need to access a file, you could derive its location from the workspace root:
"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
Upvotes: 5
Reputation: 6084
window.title
is the setting that worked for me in User Settings:
"window.title": "${activeEditorMedium}"
Other options:
// 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}",
Upvotes: 16