Skip to content

Commit

Permalink
Merge pull request #37 from ryuta46/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuta46 committed Jan 28, 2021
2 parents 32c7b76 + 07441af commit 8683144
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 99 deletions.
107 changes: 83 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,43 @@ This extension can create command sequence as one command and bind a key, or cal

## Features

* create command sequence as one command and bind a key.
* call command sequence manually.
* set interval between each command execution.
- create command sequence as one command and bind a key.
- call command sequence manually.
- set interval between each command execution.

## Extension Settings

Settings has 2 steps.
There is simple usage that uses only keybindings.json and a usage that uses settings.json.

### Simple Usage with keybindings.json

In keybindings.json, bind a key to `extension.multiCommand.execute` with passing a command sequence you want to execute as the argument.
For example:

```json
{
"key": "alt+x",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"cursorDown",
"cursorDown",
"cursorDown"
]
}
}
```
This command sequence executes "cursorDown" command 3 times.

### Usage with settings.json.

This usage is useful for resusing the defined command sequence in another command sequnce or executing the sequence manually.

In case using settings.json, the settings has 2 steps.

1. Create command sequence as one command in settings.json.
For example:

```json
"multiCommand.commands": [
{
Expand All @@ -36,22 +63,38 @@ Settings has 2 steps.
}
]
```

First sequence is named "multiCommand.down3Lines" and executes "cursorDown" command 3 times.

Second sequence is named "multiCommand.swapChar". This sequence swaps cursor's left character and the right character. If a command is executed asynchronousely, you can set time interval between each command execution using "interval" configuration(milliseconds).

You can also use an object style that uses the command name as a key instead of an array.
```json
"multiCommand.commands": {
"multiCommand.down3Lines": {
"sequence": [
"cursorDown",
"cursorDown",
"cursorDown"
]
}
}
```
This style is useful when you want to merge user settings and the workspace settings.

2. Bind a key to created command sequence in keybindings.json.
For example:
For example:

```json
{
"key": "F1",
"command": "extension.multiCommand.execute" ,
{
"key": "F1",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.down3Lines" },
"when": "editorTextFocus"
},
{
"key": "F21",
"command": "extension.multiCommand.execute" ,
{
"key": "F21",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.swapChar" },
"when": "editorTextFocus"
}
Expand All @@ -60,10 +103,20 @@ Settings has 2 steps.
You can bind a key to the command directly.

For example:

```json
{ "key": "F1", "command": "multiCommand.down3Lines", "when": "editorTextFocus"},
{ "key": "F2", "command": "multiCommand.swapChar", "when": "editorTextFocus"}
{
"key": "F1",
"command": "multiCommand.down3Lines",
"when": "editorTextFocus"
},
{
"key": "F2",
"command": "multiCommand.swapChar",
"when": "editorTextFocus"
}
```

But when you use this key bind style, Visual Studio Code may warn about the command name. see: https://github.com/ryuta46/vscode-multi-command/issues/16

### Manual Execution
Expand All @@ -77,17 +130,19 @@ You can call a defined command sequence from command palette.
If you want to call a command sequence in shorter steps, bind a key to "extension.multiCommand.execute".

For example:

```json
{
"key": "cmd+shift+m",
"command": "extension.multiCommand.execute"
}
{
"key": "cmd+shift+m",
"command": "extension.multiCommand.execute"
}
```

If you set `label` and `description` parameters in settings.json, they are displayed when you choose a command sequence.
Both parameters are optional.

For example:

```json
"multiCommand.commands": [
{
Expand All @@ -113,23 +168,21 @@ For Example:
{
"command": "multiCommand.cutAndType",
"sequence": [
"editor.action.clipboardCutAction",
{"command": "type", "args": {"text": "CUT !!"}}
"editor.action.clipboardCutAction",
{ "command": "type", "args": { "text": "CUT !!" } }
]
}
```

This sequence cut selected text and type "CUT !!".


### Find the name of the command you want to execute

1. Execute "Developer: Set Log Level..." and select "trace" in the command palette.

2. Execute command of you want to know the name.

3. You can see the name in output panel for Log(Window) process( you can set the process for output in the rightside of the output panel).
![command-name-output.png](assets/command-name-output.png)
![command-name-output.png](assets/command-name-output.png)

### Using shell commands in a command sequence

Expand All @@ -141,7 +194,10 @@ With Command Runner extension, you can write a command sequence with shell comma
{
"command": "multiCommand.checkoutDevelop",
"sequence": [
{ "command": "command-runner.run", "args": {"command": "git checkout develop"} },
{
"command": "command-runner.run",
"args": { "command": "git checkout develop" }
},
"git.sync"
]
}
Expand All @@ -151,6 +207,10 @@ See the [Command Runner document](https://marketplace.visualstudio.com/items?ite

## Release Notes

### 1.5.0
New Feature: Simple usage only with keybindings.json
New Feature: Object style settings for merging user settings and workspace settings.

### 1.4.0

Added new style for binding a key to created commands.
Expand All @@ -171,4 +231,3 @@ Now, you can use a custom multi-command immediately after adding it in the setti
### 1.0.0

Initial release.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "multi-command",
"displayName": "multi-command",
"description": "Invoke multiple commands as one command.",
"version": "1.4.0",
"version": "1.5.0",
"publisher": "ryuta46",
"repository": {
"type": "git",
Expand Down Expand Up @@ -31,7 +31,10 @@
"title": "multi-command",
"properties": {
"multiCommand.commands": {
"type": "array",
"type": [
"array",
"object"
],
"items": {
"type": "object",
"title": "command sequence",
Expand Down Expand Up @@ -69,10 +72,10 @@
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"typescript": "^2.0.3",
"typescript": "^3.9.7",
"vscode": "^1.0.0",
"mocha": "^2.3.3",
"@types/node": "^6.0.40",
"@types/node": "^7.0.7",
"@types/mocha": "^2.2.32"
}
}
9 changes: 6 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as vscode from "vscode";

export class Command {
constructor(private readonly exe: string, private readonly args: object | null) {}
constructor(
private readonly exe: string,
private readonly args: object | null
) {}

public execute() {
if (this.args === null) {
return vscode.commands.executeCommand(this.exe)
return vscode.commands.executeCommand(this.exe);
} else {
return vscode.commands.executeCommand(this.exe, this.args)
return vscode.commands.executeCommand(this.exe, this.args);
}
}
}
Loading

0 comments on commit 8683144

Please sign in to comment.