t-log

VSCodeで専用のタスクとコマンドを登録

目次

以前、以下の記事で作成した新記事作成用のスクリプトをコマンドで実行できるようにした。

タスクの登録

.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": "CreateNewPost",
"type": "shell",
"command": "node scripts/new-post.mjs",
"problemMatcher": [],
"presentation": {
"reveal": "always",
"panel": "dedicated"
}
}
]
}

tasks.jsonにコマンドを登録した。 これでVSCodeの上部のコマンドセンターから実行できるようになった。

ショートカットの登録

.vscodesettings.json
{
"workspaceKeybindings.isMyBlog": true
}
C:\Users\User\AppData\Roaming\Code\User\keybindings.json
{
"key": "ctrl+shift+t",
"command": "workbench.action.tasks.runTask",
"args": "CreateNewPost",
"when": "config.workspaceKeybindings.isMyBlog"
}

ショートカットはワークスペース内で完結して設定できないらしい。

特定のワークスペース内でのみ有効化するためworkspaceKeybindings.isMyBlogというフラグを作成し判定するようにした。

これでctrl+shift+tで新規記事を作成できるようになった。

参考にした記事