Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

vscode-commands

1.0.0 • Public • Published

VSC Commands

Logo

Trigger arbitrary commands from the statusbar. Supports passing arguments!

It comes packed with a lot of features:

  • Supports passing arguments: No other extension of this kind supports passing arguments to commands. 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.

Install

Run the following in the command palette:

ext install 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, most options are optional:

{
  "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.
    }
  ]
}

Examples

Click on the description to see the configuration used to achieve that particular result.

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"
}

Basic

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"
}

File-Related

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"
}

Markdown

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"
},
{
  "text": "$(terminal) 2",
  "command": "workbench.action.terminal.focusAtIndex2",
  "tooltip": "Focus to terminal #2"
},
{
  "text": "$(terminal) 3",
  "command": "workbench.action.terminal.focusAtIndex3",
  "tooltip": "Focus to terminal #3"
}

Terminal Tabs

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"
}

Activitus Bar

StatusBar Debugger: Replace the floating debugger widget 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"
}

StatusBar Debugger

Plays well with others

Projects+: Add some buttons for quickly switch 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"
}

Projects+

Todo+: Add a button for opening the todo file, and if that is opened add a button for viewing all your 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"
}

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"
}

Terminals

Hits:

  • Icons: here you can browse a list of supported icons. If for instance you click the first icon, you'll get a page with .octicon-alert written in it, to get the string to use simply remove the .octicon- part, so in this case the icon name would be alert.
  • Live Refresh: Even if you're crafting some local commands, it's advisable to start by adding them globally, since every time you edit your global settings your commands will be automatically refresh. Once you're done just move them to the local configuration file.

License

MIT © Fabio Spampinato

Install

npm i vscode-commands

DownloadsWeekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar