{"id":13624697,"url":"https://github.com/mkloubert/vs-script-commands","last_synced_at":"2025-04-16T01:32:03.736Z","repository":{"id":71664187,"uuid":"79733412","full_name":"mkloubert/vs-script-commands","owner":"mkloubert","description":"Add additional commands that uses (JavaScript) scripts for execution.","archived":true,"fork":false,"pushed_at":"2019-01-09T21:23:00.000Z","size":4506,"stargazers_count":17,"open_issues_count":6,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-01T22:01:59.071Z","etag":null,"topics":["ecmascript2015","javascript","nodejs","scripts","vscode-extension"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkloubert.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-22T17:36:11.000Z","updated_at":"2024-04-02T17:41:22.000Z","dependencies_parsed_at":"2023-03-04T07:00:27.508Z","dependency_job_id":null,"html_url":"https://github.com/mkloubert/vs-script-commands","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkloubert%2Fvs-script-commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkloubert%2Fvs-script-commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkloubert%2Fvs-script-commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkloubert%2Fvs-script-commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkloubert","download_url":"https://codeload.github.com/mkloubert/vs-script-commands/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223691731,"owners_count":17186873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecmascript2015","javascript","nodejs","scripts","vscode-extension"],"created_at":"2024-08-01T21:01:45.291Z","updated_at":"2024-11-08T13:31:02.516Z","avatar_url":"https://github.com/mkloubert.png","language":"TypeScript","funding_links":[],"categories":["javascript","nodejs"],"sub_categories":[],"readme":"# [DEPRECATED] vs-script-commands\n\nAdds additional commands to [Visual Studio Code](https://code.visualstudio.com/) (VS Code) that uses scripts (JavaScript) for execution.\n\n\u003cbr /\u003e\n\n**The extension is now marked as DEPRECATED ... it is RECOMMENDED to use [vscode-powertools](https://marketplace.visualstudio.com/items?itemName=ego-digital.vscode-powertools) by [e.GO Digital](https://github.com/egodigital).**\n\nIf you have suggestions and other kind of issues for that new extension, feel free to [open an issue here](https://github.com/egodigital/vscode-powertools/issues).\n\n\u003cbr /\u003e\n\n## Table of contents\n\n1. [Install](#install-)\n2. [How to use](#how-to-use-)\n   * [Changes](#changes-)\n   * [Settings](#settings-)\n      * [Commands](#commands-)\n   * [Key bindinds](#key-bindinds-)\n   * [Invoke manually](#invoke-manually-)\n   * [Status bar buttons](#status-bar-buttons-)\n   * [Quick execution](#quick-execution-)\n3. [Documentation](#documentation-)\n\n## Install [[\u0026uarr;](#table-of-contents)]\n\nLaunch VS Code Quick Open (Ctrl+P), paste the following command, and press enter:\n\n```bash\next install vs-script-commands\n```\n\nOr search for things like `vs-script-commands` in your editor:\n\n![Screenshot VSCode Extension search](https://raw.githubusercontent.com/mkloubert/vs-script-commands/master/img/screenshot1.png)\n\n## How to use [[\u0026uarr;](#table-of-contents)]\n\n### Changes [[\u0026uarr;](#how-to-use-)]\n\n* if you come from version 1.x, you should take a look at the [wiki](https://github.com/mkloubert/vs-script-commands/wiki#since-version-2x-) first ... if you have problems, you can open an [issue](https://github.com/mkloubert/vs-script-commands/issues) and/or download a version 1.x branch from [here](https://github.com/mkloubert/vs-script-commands/releases)\n\n### Settings [[\u0026uarr;](#how-to-use-)]\n\nOpen (or create) your `settings.json` in your `.vscode` subfolder of your workspace.\n\nAdd a `script.commands` section:\n\n```json\n{\n    \"script.commands\": {\n    }\n}\n```\n\n| Name | Description |\n| ---- | --------- |\n| `autoSelectWorkspace` | Select the workspace by active text editor automatically or not. Default `(false)` |\n| `commands` | One or more [commands](#commands-) to register. |\n| `disableNewVersionPopups` | Disables the display of popups that reports for a new version of that extension. Default `(false)` |\n| `globals` | Global data available for ALL commands defined by that extension. |\n| `quick` | Settings for [quick execution](#quick-execution-) feature. |\n| `showOutput` | Open output on startup or not. Default `(true)` |\n| `showInternalVSCommands` | Show internal Visual Studio Code commands in GUI or not. Default `(false)` |\n\n#### Commands [[\u0026uarr;](#settings-)]\n\nDefine one or more command, by defining its `id` and the script file, which should be executed:\n\n```json\n{\n    \"script.commands\": {\n        \"commands\": [\n            {\n                \"id\": \"mkloubert.mycommand\",\n                \"script\": \"./my-command.js\"\n            }\n        ]\n    }\n}\n```\n\nThe `./my-command.js` must have a public / exported `execute()` function:\n\n```javascript\nexports.execute = function (args) {\n    // access VSCode API (s. https://code.visualstudio.com/Docs/extensionAPI/vscode-api)\n    var vscode = require('vscode');\n\n    // access any NodeJS API provided by VSCode (s. https://nodejs.org/api/)\n    var path = require('path');\n\n    // import an own module\n    var myModule = require('./myModule');\n\n    // use the functions and classes provided by this extension\n    // s. https://mkloubert.github.io/vs-script-commands/modules/_helpers_.html\n    var helpers = args.require('./helpers');\n\n    // access a module that is part of the extentsion\n    // s. https://github.com/mkloubert/vs-script-commands/blob/master/package.json\n    var moment = args.require('moment');\n\n    // access the global data from the settings\n    var globals = args.globals;\n\n    // access the data of the entry from the settings\n    var opts = args.options;\n\n    // share / store data (while current session)...\n    // ... for this script\n    args.commandState = new Date();\n    // ... with other scripts\n    args.globalState['myCommand'] = new Date();\n\n    // access permanent data storages\n    // s. https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/common/memento.ts\n    var myAppWideValue = args.extension.globalState.get('myAppValue');  // app wide\n    args.extension.workspaceState.update('myWorkspaceValue', 'New workspace wide value');  // workspace wide\n\n    // share data between two executions\n    var prevVal = args.previousValue;  // data from the previous execution\n    args.nextValue = 'This is a value only for the next execution';  // data for the next execution\n\n    // registers for a one-time event\n    args.events.once('myCommandEvent', function(v) {\n        // 'v' should be 'William Henry Gates'\n        // if upcoming 'args.events.emit()' is called\n        args.log(\"From 'myCommandEvent': \" + v);\n    });\n\n    // emit 'myCommandEvent' event (s. above)\n    args.events.emit('myCommandEvent', 'William Henry Gates');\n\n    // logs a message to output window / channel\n    args.log('A log message');\n\n    // write to output channel of that extension\n    // s. https://code.visualstudio.com/Docs/extensionAPI/vscode-api#OutputChannel\n    args.outputChannel.appendLine('A message for the output channel.');\n\n\n    var scriptFile = path.basename(__filename);\n\n    // open HTML document in new tab (for reports e.g.)\n    args.openHtml('\u003chtml\u003eHello from my extension: ' + scriptFile + '\u003c/html\u003e', 'My HTML document').then(function() {\n        // HTML opened\n    }, function(err) {\n        // opening HTML document failed\n    });\n\n    // deploys 'index.html' to 'My SFTP server'\n    // s. https://github.com/mkloubert/vs-deploy\n    args.deploy(['./index.html'], ['My SFTP server']).then(function() {\n        // file deployed\n    }, function(err) {\n        // deployment failed\n    });\n\n    vscode.window.showInformationMessage('Hello from my extension: ' + scriptFile);\n\n    // you also can return a Promise\n    // if your command is executed async\n    return 666;\n}\n```\n\nThe `args` parameter uses the [ScriptCommandExecutorArguments](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html) interface.\n\nYou can now execute the command by anything that uses the [Visual Studio Code API](https://code.visualstudio.com/docs/extensionAPI/vscode-api#_commands):\n\n```javascript\nvar vscode = require('vscode');\n\nvscode.commands.executeCommand('mkloubert.mycommand').then(function(result) {\n    // if we look at the upper example:\n    // this should be: 666\n}, function(err) {\n    // handle an error\n});\n```\n\nA command entry provides the following properties:\n\n| Name | Description |\n| ---- | --------- |\n| `arguments` | One or more arguments for the callbacks. |\n| `askForArgument` | Defines if the GUI asks for an argument when invoke manually or not. Default `(false)` |\n| `async` | Invokes command async or not. Default `(true)` |\n| `button` | Settings for optional [button](#status-bar-buttons-) in the status bar. |\n| `cached` | Cache script or not. Default `(false)` |\n| `commandState` | The initial value for [commandState](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html#commandstate) property. Default `{}` |\n| `continueOnError` | Continue on error or cancel. Default `(true)` |\n| `description` | The description for the command. |\n| `displayName` | The custom display name. |\n| `id` | The ID of the command. |\n| `onActiveEditorChanged` | Is invoked when the active text editor has been changed. Default `(false)` |\n| `onClose` | Executes the command on VSCode closes or not. Default `(false)` |\n| `onConfigChanged` | Is invoked after `settings.json` has been changed. Default `(false)` |\n| `onEditorChanged` | Is invoked after a text editor changed. Default `(false)` |\n| `onFileChanged` | Is invoked when a file has been changed. Default `(false)` |\n| `onFileClosed` | Is invoked when a file has been closed. Default `(false)` |\n| `onFileDeleted` | Is invoked when a file has been deleted. Default `(false)` |\n| `onFileOpened` | Is invoked when a file has been opened. Default `(false)` |\n| `onNewFile` | Is invoked when a file has been created. Default `(false)` |\n| `onSaved` | Is invoked when a file has been saved. Default `(false)` |\n| `onStartup` | Executes the command on startup or not. Default `(false)` |\n| `onWillSave` | Is invoked when a file is going to be saved. Default `(false)` |\n| `options` | Additional data for the execution. |\n| `script` | The path to the script to execute. IF YOU USE A RELATIVE PATH: The path is relative to your workspace. |\n| `sortOrder` | The sort order (for the GUI). Default `0` |\n| `suppressArguments` | Supress own arguments of the extension or not. Default `(false)` |\n\n### Key bindinds [[\u0026uarr;](#how-to-use-)]\n\nAfter defining one or more commands, you can open your [keybindings.json](https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization) file and set shortcuts for them, by selecting `File \u003e Preferences \u003e Keyboard Shortcuts` (`Code \u003e Preferences \u003e Keyboard Shortcuts` on Mac) in your editor:\n\n![Demo Key bindinds](https://raw.githubusercontent.com/mkloubert/vs-script-commands/master/img/demo1.gif)\n\n### Invoke manually [[\u0026uarr;](#how-to-use-)]\n\nPress `F1` to open the list of commands and enter one of the following commands:\n\n![Demo Invoke manually](https://raw.githubusercontent.com/mkloubert/vs-script-commands/master/img/demo2.gif)\n\n| Name | Description | Command |\n| ---- | ---- | --------- |\n| `Script commands: Execute command` | Executes a command defined by that extension. | `extension.scriptCommands.execute` |\n| `Script commands: Execute VSCode command` | Executes another command that is available in VSCode. | `extension.scriptCommands.executeVSCode` |\n| `Script commands: Quick execution` | Executes a JavaScript expression quickly. | `extension.scriptCommands.quickExecution` |\n| `Script commands: Select workspace` | Changes the current workspace, s. [Multi-root Workspaces](https://code.visualstudio.com/docs/editor/multi-root-workspaces). | `extension.scriptCommands.selectWorkspace` |\n\n### Status bar buttons [[\u0026uarr;](#how-to-use-)]\n\nYou can activate buttons for your commands in the status bar, by defining the `button` property:\n\n```json\n{\n    \"script.commands\": {\n        \"commands\": [\n            {\n                \"id\": \"mkloubert.mycommand\",\n                \"script\": \"./my-command.js\",\n                \n                \"button\": {\n                    \"text\": \"My command\",\n                    \"tooltip\": \"This is a tooltip for my command\"\n                }\n            }\n        ]\n    }\n}\n```\n\n![Demo Status bar buttons](https://raw.githubusercontent.com/mkloubert/vs-script-commands/master/img/demo3.gif)\n\n| Name | Description |\n| ---- | --------- |\n| `color` | The custom (text) color for the button. |\n| `isRight` | Set button on the right side or not. Default `(false)` |\n| `priority` | The custom priority. |\n| `show` | Show button on startup or not. Default `(true)` |\n| `text` | The caption for the button. |\n| `tooltip` | The tooltip for the button. |\n\n### Quick execution [[\u0026uarr;](#how-to-use-)]\n\nPress `F1` to open the list of commands and select `Script commands: Quick execution` to execute any JavaScript expression (execute `$help` to open a help tab which lists all available features, like functions and variables):\n\n![Demo Quick execution](https://raw.githubusercontent.com/mkloubert/vs-script-commands/master/img/demo4.gif)\n\nYou can define custom settings for the feature:\n\n```json\n{\n    \"script.commands\": {\n        \"quick\": {\n            \"noResultInfo\": false,\n            \"showResultInTab\": true,\n            \n            \"state\": {\n                \"MK\": 23979,\n                \"TM\": \"1979-09-05 23:09:19.079\"\n            }\n        }\n    }\n}\n```\n\n| Name | Description |\n| ---- | --------- |\n| `cwd` | The initial current directory for the executions. |\n| `disableHexView` | Do not show binary data in 'hex view'. Default: `(false)` |\n| `noResultInfo` | Do not show results of executions. Default: `(false)` |\n| `saveResultsToState` | Save all results to `$state` variable or not. Default: `(false)` |\n| `showResultInTab` | Show results in tab instead of a popup or not. Default: `(false)` |\n| `saveToGlobalHistory` | Save entries, that are stored automatically, to global history instead to workspace history. Default: `(false)` |\n| `saveToHistory` | Automatically save entries to history or not. Default: `(false)` |\n| `state` | The initial state value. |\n\n## Documentation [[\u0026uarr;](#table-of-contents)]\n\nThe full API documentation can be found [here](https://mkloubert.github.io/vs-script-commands/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkloubert%2Fvs-script-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkloubert%2Fvs-script-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkloubert%2Fvs-script-commands/lists"}