Commands
Trigger arbitrary commands from the statusbar. Supports passing arguments!
It comes packed with features:
- Supports passing arguments: this feature makes it quite powerful, for instance adding the ability to trigger custom terminal commands via Terminals, more about it below.
- Configuration based: no need to create an extension just for adding some simple items to the statusbar, just edit the configuration.
- Global and local commands: define commands in your settings to make them global, define them in a local configuration file to make them project-specific.
- Configurable: many aspects of the statusbar items can be configured, including text, tooltip, color, position etc.
- Per language commands: show a particular statusbar item only if the currently opened file's language matches a provided regex.
- Per file commands: show a particular statusbar item only if the currently opened file's path matches a provided regex.
- Per workspace file: show a particular statusbar item only if a file's path that matches a provided regex is found in the workspace.
Install
Follow the instructions in the Marketplace, or run the following in the command palette:
ext install fabiospampinato.vscode-commands
Usage
It adds 2 commands to the command palette:
'Commands: Edit Configuration' // Open the local configuration file
'Commands: Refresh' // Force a refresh, must be called after editing the local configuration
Configuration
Run the Commands: Edit Configuration
command to create the local configuration file. If you want to define global commands simply add them to your Visual Studio Code settings under the key commands.commands
.
The configuration is an object that looks like this:
{
"commands": [ // Array of commands
{ // An object describing a command, most entries are optional
"alignment": "left", // Should the item be placed to the left or right?
"priority": 0, // The priority of this item. Higher value means the item should be shown more to the left
"color": "#FFCC00", // The foreground color for this item
"text": "$(gear) Settings", // The text to show for the entry
"tooltip": "Open User Settings", // The tooltip text when you hover over this item
"command": "workbench.action.openGlobalSettings", // Command to execute
"arguments": [1, 2, 3], // Arguments to pass to the command handler
"filterLanguageRegex": "markdown", // Show only if current file's language matches this regex. Requires double escaping
"filterFileRegex": ".*\\.ext", // Show only if the current file's path matches this regex. Requires double escaping
"filterWorkspaceFileRegex": "**/.*\\.ext" // Show only if a file's path that matches this regex is found in the workspace. Requires double escaping
}
]
}
Examples
Simple commands
- Add buttons for opening the command palette, the global settings and toggling zen mode.
{
"text": "$(chevron-right)",
"command": "workbench.action.showCommands",
"tooltip": "Show commands"
},
{
"text": "$(gear)",
"command": "workbench.action.openGlobalSettings",
"tooltip": "Settings"
},
{
"text": "Zen",
"command": "workbench.action.toggleZenMode",
"tooltip": "Toggle Zen mode"
}
- Add some file-related buttons: create a new untitled file and save all files.
{
"text": "$(file-code) New file",
"command": "workbench.action.files.newUntitledFile",
"tooltip": "New file"
},
{
"text": "$(checklist) Save all",
"command": "workbench.action.files.saveAll",
"tooltip": "Save all files"
}
- Add a button for showing the Markdown preview to the side, only when a Markdown file is currently active.
{
"text": "$(markdown)",
"command": "markdown.showPreviewToSide",
"tooltip": "Open markdown preview",
"filterFileRegex": ".*\\.md"
}
Implementing existing extensions' functionality
- Terminal Tabs: Add buttons for easy switching to the N-th terminal instance.
{
"text": "$(terminal) 1",
"command": "workbench.action.terminal.focusAtIndex1",
"tooltip": "Focus to terminal [#1](https://github.com/fabiospampinato/vscode-commands/issues/1)"
},
{
"text": "$(terminal) 2",
"command": "workbench.action.terminal.focusAtIndex2",
"tooltip": "Focus to terminal [#2](https://github.com/fabiospampinato/vscode-commands/issues/2)"
},
{
"text": "$(terminal) 3",
"command": "workbench.action.terminal.focusAtIndex3",
"tooltip": "Focus to terminal [#3](https://github.com/fabiospampinato/vscode-commands/issues/3)"
}
- Activitus Bar: Replace the activity bar with buttons in the statusbar.
{
"text": "$(file-directory)",
"command": "workbench.view.explorer",
"tooltip": "Explorer"
},
{
"text": "$(search)",
"command": "workbench.view.search",
"tooltip": "Search"
},
{
"text": "$(repo-forked)",
"command": "workbench.view.scm",
"tooltip": "Source Control"
},
{
"text": "$(bug)",
"command": "workbench.view.debug",
"tooltip": "Debug"
},
{
"text": "$(package)",
"command": "workbench.view.extensions",
"tooltip": "Extensions"
}
- StatusBar Debugger: Replace the default floating debugger with some statusbar buttons. That extension is actually a bit more powerful than this, but if you don't need all it's functionalities the following configuration might be good enough.
{
"text": "$(triangle-right)",
"command": "workbench.action.debug.start",
"tooltip": "Start debugging"
},
{
"text": "$(primitive-square)",
"command": "workbench.action.debug.stop",
"tooltip": "Stop debugging"
}
Plays well with others
Projects+: Add some buttons for quickly switching between projects.
{
"text": "$(file-submodule)",
"command": "projects.open",
"tooltip": "Open a project"
},
{
"text": "Projects+",
"command": "projects.openByName",
"arguments": ["vscode-projects-plus"],
"tooltip": "Open Projects+"
},
{
"text": "Todo+",
"command": "projects.openByName",
"arguments": ["vscode-todo-plus", true],
"tooltip": "Open Todo+ in a new window"
},
{
"text": "My Group",
"command": "projects.openByName",
"arguments": ["My Group", false, true],
"tooltip": "Switch to the My Group"
}
Todo+: Add a button for opening the todo file, and if that is opened add a button for viewing all todos across your projects, using Projects+ Todo+.
{
"text": "$(check)",
"command": "todo.open",
"tooltip": "Open todo"
},
{
"text": "$(checklist)",
"command": "projects.todo",
"tooltip": "Open global todo",
"filterLanguageRegex": "todo"
}
Terminals: Trigger custom advanced terminal commands.
{
"text": "$(terminal)",
"command": "terminals.runTerminal",
"tooltip": "Run a terminal"
},
{
"text": "Init",
"command": "terminals.runTerminalByName",
"arguments": ["init"],
"tooltip": "Init the project"
},
{
"text": "Serve",
"command": "terminals.runTerminalByName",
"arguments": ["serve"],
"tooltip": "Serve the project"
}
Hints
- Icon: here you can browse a list of supported icons.
- Live Refresh: even if you're crafting some local commands, it's advisable to start by adding them globally because every time you edit your global settings your commands will be automatically refreshed. Once you're done just move them to the local configuration file.
License
MIT © Fabio Spampinato