VSCodeで専用のタスクとコマンドを登録
以前、以下の記事で作成した新記事作成用のスクリプトをコマンドで実行できるようにした。
タスクの登録
{ // 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の上部のコマンドセンターから実行できるようになった。
ショートカットの登録
{ "workspaceKeybindings.isMyBlog": true}{ "key": "ctrl+shift+t", "command": "workbench.action.tasks.runTask", "args": "CreateNewPost", "when": "config.workspaceKeybindings.isMyBlog"}ショートカットはワークスペース内で完結して設定できないらしい。
特定のワークスペース内でのみ有効化するためworkspaceKeybindings.isMyBlogというフラグを作成し判定するようにした。
これでctrl+shift+tで新規記事を作成できるようになった。