keybinding build_with with cmd in sublime - sublimetext3

I want to call a specific build command stored in an external plugin of Sublime. The .sublime.build looks like this.
{
"selector": "text.html.markdown.knitr",
"working_dir": "${project_path:${folder}}",
"env": { "LANG": "en_US.UTF-8" },
"cmd": [ "Rscript -e \"library(knitr); knit('$file', output='$file_path/$file$
"shell": true,
"variants":
[
{
"name": "Run",
"working_dir": "$file_path",
"shell_cmd": "Rscript -e \"rmarkdown::render(input = '$file')\""
}
]
}
It uses cmd to simply call an external command. I would like to create a keybinding that automatically selects the "Run" variant of the .sublime.build. I tried with the following code:
{ "keys": ["ctrl+shift+b"], "command": "build", "args": {"build_system": "/Packages/knitr/knitr-Markdown.sublime-build", "variant": "Run" }},
Unfortunately, the shell returns
shell_cmd or cmd is required
[cmd: None]
[dir: /Users/serg/Desktop]
[path: /Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/serg/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/opt/X11/bin]
[Finished]
Any help is appreciated

First of all, your current build file is invalid, the JSON itself is not valid. I'm not sure if this is a copy & paste error. If not, use a JSON Validator to fix the syntax.
Next, you need to provide the command in the correct syntax. cmd is expecting the command as an array. Since your cmd is incomplete, I'll provide a different example.
Wrong syntax
"cmd": ["compiler --arg source.c"]
Correct syntax
"cmd": ["compiler, "--arg", "source.c"]
For reference, here's one of the build files from the R-IDE package:
{
"selector": "text.html.markdown.rmarkdown",
"working_dir": "$file_path",
"cmd": [
"Rscript", "-e",
"rmarkdown::render('$file_name', encoding = 'UTF-8')"
],
"osx":{
"path": "/Library/TeX/texbin:/usr/local/bin:$PATH"
}
}

Related

Set a dev container to open a terminal

Is it possible in the dev container specification to specify one or more terminals to be opened as part of the dev container?
My use case is that I'd like to open two terminals for the user:
Build and host the app.
Build and run the app API.
The idea is simply to save the user's time of having to open up the terminals themselves and run the relevant commands.
Same terminal
If you don't need the logs in separate terminals, you can use the postStartCommand lifecycle script.
Add your commands to the devcontainer.json file, with the commands separated by &&; use nohup as in this example to leave the processes running:
"postStartCommand": "echo hello && echo world"
Separate terminals
If you want separate terminals, you can create a custom task; the page also contains info on how to further customize your tasks.
// .vscode/tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Host",
"type": "shell",
"command": "echo hello",
"group": "build",
"presentation": {
"group": "buildGroup",
"reveal": "always",
"panel": "new",
"echo": false,
}
},
{
"label": "Build API",
"type": "shell",
"command": "echo world",
"group": "build",
"presentation": {
"group": "buildGroup",
"reveal": "always",
"panel": "new",
"echo": false,
}
},
{
"label": "Build All",
"dependsOn": [
"Build Host",
"Build API"
],
"group": "build",
"runOptions": {
"runOn": "folderOpen" // This starts both tasks when the container is started
},
}
]
}
With Run and Debug
Finally, depending on what project your are working on, you can use the launch.json file to set a custom run command. Here you can find the documentation.

VSCode using relative paths in build task on remote set up

I'm trying to add a build task to build the current file, just a simple "make path/to/file.o". I'm using vscode on windows 10 over a remote SSH connection to linux.
However, if I use ${relativeFileDirname} it converts the path separators to windows format. Eg...
${fileDirname}=/home/me/git/project/data/source
${relativeFileDirname}=data\source
I've read about explorer.copyRelativePathSeparator. Can that be applied to the build task in tasks.json? Or is there another way?
This is the build task...
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/make",
"args": [
"${relativeFileDirname}/${fileBasenameNoExtension}.o"
],
"options": {
"cwd": "/home/me/git/project"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/gcc",
"presentation": {
"clear": true
}
}
Thanks.
There is an extension for Visual Studio Code for this purpose that, after many failed attempts to use string substitution with bash built-ins and sed, was the only working solution for me:
"customOptions": "--workdir /home/user/${command:extension.commandvariable.file.relativeFileDirnamePosix}",

How can I call arm-none-eabi-gdb with -x parameter

I want to call arm-none-eabi-gdb with -x parameter when launch debugger after installing cortex-debug. How can I do in launch.json or setting.json, thanks for your help.
You may try adding the following task to our tasks.json the following:
{
"label": "flash",
"type": "shell",
"command": "arm-none-eabi-gdb",
"args": [
"-x=\"${workspaceFolder}/.vscode/flash.gdb\"",
],
"group": "build",
"problemMatcher": [],
"dependsOn":["build"]
},
(of course this assume you have another task called "build" and that your "flash" task depends on it. this is just an example of how to add the -x argument)

Issue passing Node arguments to PM2

I want to start a process using PM2, but it doesn't seem to pick up node arguments relative to the current working directory.
Running this from /path/to/dir/ works:
pm2 start dist/main.js --node-args="-r ./tsconfig-paths-bootstrap.js" -- -c config.json
whereas using this ecosystem file:
{
"apps": [
{
"name": "server",
"script": "dist/main.js",
"instances": 2,
"exec_mode": "cluster",
"cwd": "/path/to/dir/",
"args": [
"-c",
"config.json"
],
"node_args": [
"-r",
"./tsconfig-paths-bootstrap.js"
],
"watch": false
}
]
}
and running:
pm2 start server
gives me the following error:
Error: Cannot find module './tsconfig-paths-bootstrap.js'
How can this be fixed?
Try this:
"node_args": ["-r ./tsconfig-paths-bootstrap.js"]
Check this
And make sure your file is in same directory else you need to give full p ath to file.

Hotkey for running command

I want to create a keyboard shortcut in Sublime Text 3.
The command I want to run is something like this:
[make.sublime-build]
{
"name": "boot-dev-svr",
"cmd": ["java","-jar","D:\\prg\\boot\\boot-1.1.1.jar","development"],
"working_dir": "D:/smx",
"path": "C:/Windows/System32",
}
The key I want to map this action to is F5:
[Default (Windows).sublime-keymap - User]
[
{ "keys": ["f5"], "command": "BLAH BLAH BLAH" },
]
Seems like it should be simple, but "cmd" and "command" seem to be fundamentally different. I have not managed to get it to work.
How do I put these things together to do what I want in Sublime Text 3?
Have you tried putting the actual command in []
That worked for me.
Another solution would be to update Sublime Text 3 to the latest release, sometimes that fixes the bug.
Hope I helped!
EDIT
Try removing the comma from the end of make.subime-build, like this
{
"name": "boot-dev-svr",
"cmd": ["java","-jar","D:\\prg\\boot\\boot-1.1.1.jar","development"],
"working_dir": "D:/smx",
"path": "C:/Windows/System32",
}
This is what I wound up doing, which seems to work, more or less.
Build:
{
"cmd": ["python","prj.py","--runmake","serve"],
"working_dir": "D:/smx",
"path": "C:/Python27",
"variants":
[
{
"name": "boot-dev-svr",
"cmd": ["java","-jar","D:\\prg\\boot\\boot-1.1.1.jar","development"],
"working_dir": "D:/smx",
"path": "C:/Windows/System32",
},
]
}
Keymap:
[
{ "keys": ["f5"], "command": "build", "args": {"variant": "boot-dev-svr"} },
]

Resources