Search code examples
visual-studio-codevscode-tasks

VS Code Tasks: Open Selection


I'v created a task that will open the file that correponds to the path i have selected:

{
        "type": "shell",
        "label": "Open Selection",
        "command": "myFile=`echo ${workspaceFolder}${selectedText} | sed 's/\\.css/\\.scss/g;s/\\.\\.//g;`;code $myFile",
        "problemMatcher": []
    },

I'd like to insert my cursor into an href, do "Expand Selection" then do "Open Selection". But Expand Selection grabs the quotes surrounding the path. I've solved this successfully in Terminal (OS X), but as a VS Code task it fails...

"command": "myFile=`echo ${workspaceFolder}${selectedText} | sed 's/\\.css/\\.scss/g;s/\\.\\.//g;s/\\\"//g`;code $myFile"

that fails in VS Code. with the error:

/bin/bash: command substitution: line 0: unexpected EOF while looking for matching `''

But oddly, when i copy the command that VS Code errors on in out

> Executing task: myFile... <

and run it in Terminal, it works. So I'm stumped, why a command will succeed in Terminal and fail in VS Code's terminal?


Solution

  • never mind, it was user error. Here is the completed task:

    {
            "type": "shell",
            "label": "Open Selection",
            "command": "myFile=`echo echo ${workspaceFolder}${selectedText} | sed 's/\\.css/\\.scss/g; s/\\.\\.//g;s/\\\"//g'`;code $myFile",
        },