What The Beep?!
This extension provides the capability to play an audio file and send
VS Code and/or desktop notifications after built-in VS Code events, including:
Beep via Terminal Event
Beeps and notifications can be triggered via terminal events. Simply
configure the what-the-beep.terminalActions setting:
{
"what-the-beep.terminalActions": [
{
// Any combination/subset of the following fields can be set. Their
// names are self-explanatory and VS Code setting auto-completion
// will provide useful hints on how to configure each of these values.
"trigger": ...,
"desktopNotification": ...,
"notification": ...,
}
],
},
The above configuration will cause the default beep to be played (along
with any other notification actions). However, you can also configure
other beeps and actions to be triggered by terminal events:
{
"what-the-beep.terminalActions": [
// Beeps with a different builtin sound
{
"trigger": ...,
"command": "what-the-beep.beep",
"args": {
"builtin": "error",
}
},
// Runs a different VS Code command for the given trigger
{
"trigger": ...,
"command": "workbench.action.terminal.copyLastCommandOutput",
}
],
},
Template Variables
Notification messages and desktop notification titles/messages can include
${variable} placeholders, which are filled in from the terminal command that
triggered the action:
{
"what-the-beep.terminalActions": [
{
"trigger": { "exitCode": -1 },
"desktopNotification": {
"title": "Failed on ${branch}",
"message": "`${command}` exited with ${exitCode} after ${duration}",
},
}
],
},
| Variable |
Value |
${command} |
The command line that was run |
${exitCode} |
The command's exit code (empty if unknown) |
${duration} |
How long the command ran (e.g. 450ms, 3.2s, 2m 5s, 1h 3m) |
${branch} |
The current git branch (or short commit hash when detached) of the repository containing the terminal's directory |
${cwd} / ${cwdBasename} |
The terminal's working directory (full path / folder name) |
${workspaceFolder} / ${workspaceFolderBasename} |
The workspace folder containing the working directory (full path / folder name) |
${terminalName} |
The terminal's name |
${env:NAME} |
The value of environment variable NAME |
${match}, ${match:1}, ${match:name} |
The whole match, a numbered group, or a named group from trigger.commandLineRegex |
Unknown variables are left as-is, so typos are easy to spot.
Custom Variables
Define your own variables with the what-the-beep.variables setting. A value is
either a template string or an object that extracts part of another template with
a regex:
{
"what-the-beep.variables": {
// A template that combines other variables
"where": "${workspaceFolderBasename} @ ${branch}",
// The ticket ID from the branch name (e.g. `feature/ABC-123-fix` -> `ABC-123`)
"ticket": {
"from": "${branch}",
"regex": "[A-Z]+-\\d+",
"default": "no ticket",
},
// Capture groups can be rearranged with `replace` (`$1`, `$<name>`, `$&`, `$$`)
"testName": {
"from": "${command}",
"regex": "-run\\s+(\\S+)",
"replace": "test $1",
"default": "all tests",
},
},
"what-the-beep.terminalActions": [
{
"desktopNotification": {
"title": "${where} (${ticket})",
"message": "Finished ${testName}",
},
}
],
},
Regex objects also accept flags (e.g. "i"). When the regex doesn't match,
the variable uses default (an empty string if unset). Custom variables can't
reuse a built-in variable's name.
Beep via Extensions
Simply use the provided command in your workflow or other extension logic
to play these audio files:
// Play a built-in audio sound
vscode.commands.executeCommand(`what-the-beep.beep`, {
builtin: 'error',
});
// Play a provided audio file
vscode.commands.executeCommand(`what-the-beep.beep`, {
file: '/path/to/file.mp3'
});
Beep via Keybinding
See the below keybindings.json file for example usage:
{
// Make a beep sound
{
"command": "what-the-beep.beep",
"key": "ctrl+shift+b"
},
// Play a specific audio file
{
"command": "what-the-beep.beep",
"args": {
"file": "/path/to/your/file.wav",
},
"key": "...",
},
// Play a builtin sound
{
"command": "what-the-beep.beep",
"args": {
// This can be one of break, error, laser, success, warning
"builtin": "laser",
},
"key": "...",
},
}
Supported Audio Files
This extension uses the NodeJS sound-play
package under the hood and, therefore, supports all audio extensions supported
by that library.
Currently, it supports .mp3, .wav, and other extension files (depending on OS type).
Only Windows and Mac OS are currently supported.