VNote supports a simple task system like VSCode Tasks, which enables executing third-party programs easily.
VNote will try to load tasks from three locations:
default_config_folder/tasks for built-in tasksuser_config_folder/tasks for user-defined tasksnotebook_config_folder/tasks for tasks defined by this notebookA task is defined by a *.json entry file.
Click the Add Task item on the task menu, which will open the user-defined tasks folder.
New a folder named hello and under it create a file named hello.json. Edit the JSON file as:
{
"command": "echo 'Hello Tasks'"
}
Reload tasks in the menu and we could see that a new task named hello is listed on the menu. Click it to run the task.
{
"label": "Hello",
"icon": "tasks-solid.svg",
"shortcut": "Alt+H, T",
"command": "echo",
"args": [
"Hello tasks!"
]
}
The icon file tasks-solid.svg should be saved alongside the JSON entry file.
Tasks could be embedded infinitely. Sub-tasks will inherit most properties from parent.
{
"label": "Hello Tasks",
"icon": "tasks-solid.svg",
"shortcut": "Alt+H, T",
"command": "echo",
"args": ["Hello tasks!"],
"tasks": [
{
"label": "Hello Cat",
"icon": "cat-solid.svg",
"shortcut": "Alt+H, C",
"args": ["Hello cat!"]
},
{
"label": "Hello Dove",
"icon": "dove-solid.svg",
"shortcut": "Alt+H, D",
"args": ["Hello dove!"]
},
{
"label": "Hello Fish",
"icon": "fish-solid.svg",
"shortcut": "Alt+H, F",
"args": ["Hello fish!"]
}
]
}
The type property of one task defines how the command will be executed.
shell: Default, will run the command as a shell commandprocess: Will run the command as a standalone program
{
"type": "process",
"label": "Open File with",
"args": ["${buffer}"],
"tasks": [
{
"label": "Typora",
"icon": "Typora.svg",
"command": "C:\\Programs\\Typora0.9.98\\x64\\Typora.exe"
},
{
"label": "VS Code",
"icon": "vscode.svg",
"command": "C:\\Users\\tootal\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
}
]
}
::: alert-info
Yep, tootal is the contributor who initiated the Task system of VNote!
:::
VNote does not provide a terminal. We may need to use start or gnome-terminal or konsole to run some programs in terminal.
{
"label": "Vim",
"icon": "vim.svg",
"type": "process",
"command": "gnome-terminal",
"args": [
"--execute",
"vim",
"${buffer}"
]
}
Provide a locale string JSON object to provide localization.
{
"label": {
"en_US": "Hello",
"zh_CN": "你好"
}
}
We could use windows/linux/osx keyword to specify options for different platforms.
{
"type": "process",
"label": "Open File with",
"args": ["${buffer}"],
"tasks": [
{
"label": "Typora",
"icon": "Typora.svg",
"windows": {
"command": "C:\\Programs\\Typora0.9.98\\x64\\Typora.exe"
},
"linux": {
"command": "/usr/bin/typora"
}
},
{
"label": "VS Code",
"icon": "vscode.svg",
"windows": {
"command": "C:\\Users\\tootal\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
},
"linux": {
"command": "/usr/bin/code"
}
}
]
}
A task could have several options, some of them are mandatory.
We will use [m] to mark the mandatory options, [l] to mark the options supporting localization.
version: the version of the task filelabel[l]: the name of the tasktype: the type of task; shell(default)/processcommand[l]: the command to executeargs[l]: the arguments passed to the commandoptions: options for runnig task
cwd: current working directory to run task; will try current notebook root folder, then current buffer folder, and then current task file folder in order if missingenv: environment variables for running taskshell: options for tasks of shell type
executable: the shell executable file; Powershell.exe by default on Windows and /bin/bash by default on Linux/macOSargs: the arguments to start shelltasks: define sub-tasksinputs: define input variables
id[m]: ID of the input variabletype: promptString (default, prompt for user input) or pickString (prompt for user selection)description[l]: description of the input variabledefault[l]: default valuepassword: whether use password mode for promptString typeoptions[l]: options defined for pickString typewindows: options for Windows systemlinux: options for Linux systemosx: options for macOS systemA task could use variables provided by VNote in the form ${variableName}. Variables could provide useful information to the task when running.
Variables could be used in options command/args/options.cwd/options.env.
Notebook-related variables:
notebookFolder: path of the notebook root foldernotebookFolderNamenotebookNamenotebookDescriptionBuffer-related variables:
buffer: path of current bufferbufferNotebookFolder: path of the notebook root folder of the notebook of current bufferbufferRelativePathbufferNamebufferBaseNamebufferDir: folder of current bufferbufferExt: extension suffix of current bufferselectedText: selected text of current buffer view windowTask-related variables:
cwd: current working directorytaskFile: the path of the task entry filetaskDir: the path of the directory containing the task entry fileexeFile: the path of VNote executable filepathSeparator: the platform-dependent path separatornotebookTaskFolder: the path of current notebook task folderuserTaskFolder: the path of user task folderappTaskFolder: the path of default task folderuserThemeFolder: the path of user theme folderappThemeFolder: the path of default theme folderuserDocsFolder: the path of user docs folderappDocsFolder: the path of default docs folderOther specifal variables:
${magic:snippet_name}${env:env_name}${config:[main|session].json_object_path}
main for the main configurations from vnotex.json and session for the session configurations from session.jsonarr[index] to access a JSON array${config:main.core.shortcuts.FullScreen} will get the shortcut of FullScreenA task could use input variables to prompt for user inputs via ${input:input_id}.
There are now two types of input variables:
promptStringpickString
{
"command": "echo",
"args": ["${input:what}"],
"inputs": [
{
"id": "what",
"type": "promptString",
"description": "Type something, it will show in output panel."
}
]
}
A task could execute a shell command and get its output via shell variables like ${shell:shell_command}.
${shell:git rev-parse --abbrev-ref HEAD} → master${shell:whoami} → tootal${shell:dig github.com -4 +short} → 52.69.186.44There is a built-in task named Git which locates in the default configuration task folder.
Compile and run:
{
"command": "g++ \"${buffer}\" -o \"${bufferBaseName}\"; if ($?) { start cmd \"/c `\"${bufferBaseName}`\" & pause\" }"
}
Run a HTTP server:
{
"command": "start cmd.exe \"/c python -m http.server\" ; start http://localhost:8000"
}