Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add favorite commands to history (fixes ryu1kn/vscode-edit-with-shell#13) #37

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Leverage your favourite shell commands to edit text.

* Edit the selected text by piping it through shell commands.
The same text is also available as an environment variable, `ES_SELECTED`.
* The path of the current file is available as an environment variable, `ES_FILEPATH`.
* Insert the output of shell commands at the cursor position.
* Records command history: you can edit and reuse past commands.
* Use the shell you like. For example, if you have Bash on Windows, you can specify Bash as your shell for this extension.
* Register up to 5 quick commands that can be invoked by keyboard shortcuts.
* Register up to 25 quick commands that can be invoked by keyboard shortcuts.
* Support multi cursors.

![Edit with Shell Command](https://raw.githubusercontent.com/ryu1kn/vscode-edit-with-shell/master/images/animations/public.gif)
Expand Down Expand Up @@ -41,7 +42,7 @@ A couple of requests from me when you raise an github issue.

* `EditWithShell: Run quick command 1` (**Command ID:** `editWithShell.runQuickCommand1`)

Run quick command 1. **You have quick commands up to 5**, i.e. `editWithShell.runQuickCommand5`
Run quick command 1. **You have quick commands up to 25**, i.e. `editWithShell.runQuickCommand25`

## Configurations

Expand All @@ -51,17 +52,21 @@ A couple of requests from me when you raise an github issue.

* `editWithShell.processEntireTextIfNoneSelected` (default: `false`)

Pipe the entire text to the shell command if no text is selected
Pipe the entire text to the shell command if no text is selected (it can be overridden on a per command basis)

* `editWithShell.promptModifyCommand` (default: `true`)

Display a prompt to modify the selected command

* `editWithShell.favoriteCommands` (default: `[]`)

List of commands that can be activated by quick commands. Each element must have a command ID and command. e.g:
Commands listed by default in the history and activable by quick commands. Each element must have a property `command`. In order to be used as a quick command, the property `id` must be set. Also, it can optionally have the boolean property `processEntireTextIfNoneSelected` (it'll override the extension setting `editWithShell.processEntireTextIfNoneSelected`).

```
"editWithShell.favoriteCommands": [
{
"id": "extract-email-and-sort-on-address-book",
"command": "cut -d, -f3 | sort"
"command": "cut -d, -f3 | sort",
"processEntireTextIfNoneSelected": true
},
{
"id": "insert-melbourne-time",
Expand All @@ -75,7 +80,11 @@ A couple of requests from me when you raise an github issue.

ID of a favorite command triggered with quick command 1. e.g. `"insert-melbourne-time"` of `favoriteCommands` config value example.

**You have quick commands up to 5**, i.e. `editWithShell.quickCommand5`.
**You have quick commands up to 25**, i.e. `editWithShell.quickCommand25`.

* `editWithShell.clearFavoriteCommands` (default: `true`)

When clearing command history, clear also favorite commands

* `editWithShell.shell.linux` (default: `"/bin/sh"`)

Expand Down
216 changes: 214 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,27 @@
"onCommand:editWithShell.runQuickCommand2",
"onCommand:editWithShell.runQuickCommand3",
"onCommand:editWithShell.runQuickCommand4",
"onCommand:editWithShell.runQuickCommand5"
"onCommand:editWithShell.runQuickCommand5",
"onCommand:editWithShell.runQuickCommand6",
"onCommand:editWithShell.runQuickCommand7",
"onCommand:editWithShell.runQuickCommand8",
"onCommand:editWithShell.runQuickCommand9",
"onCommand:editWithShell.runQuickCommand10",
"onCommand:editWithShell.runQuickCommand11",
"onCommand:editWithShell.runQuickCommand12",
"onCommand:editWithShell.runQuickCommand13",
"onCommand:editWithShell.runQuickCommand14",
"onCommand:editWithShell.runQuickCommand15",
"onCommand:editWithShell.runQuickCommand16",
"onCommand:editWithShell.runQuickCommand17",
"onCommand:editWithShell.runQuickCommand18",
"onCommand:editWithShell.runQuickCommand19",
"onCommand:editWithShell.runQuickCommand20",
"onCommand:editWithShell.runQuickCommand21",
"onCommand:editWithShell.runQuickCommand22",
"onCommand:editWithShell.runQuickCommand23",
"onCommand:editWithShell.runQuickCommand24",
"onCommand:editWithShell.runQuickCommand25"
],
"main": "./out/extension",
"contributes": {
Expand Down Expand Up @@ -71,6 +91,106 @@
"command": "editWithShell.runQuickCommand5",
"title": "Run quick command 5",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand6",
"title": "Run quick command 6",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand7",
"title": "Run quick command 7",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand8",
"title": "Run quick command 8",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand9",
"title": "Run quick command 9",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand10",
"title": "Run quick command 10",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand11",
"title": "Run quick command 11",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand12",
"title": "Run quick command 12",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand13",
"title": "Run quick command 13",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand14",
"title": "Run quick command 14",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand15",
"title": "Run quick command 15",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand16",
"title": "Run quick command 16",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand17",
"title": "Run quick command 17",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand18",
"title": "Run quick command 18",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand19",
"title": "Run quick command 19",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand20",
"title": "Run quick command 20",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand21",
"title": "Run quick command 21",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand22",
"title": "Run quick command 22",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand23",
"title": "Run quick command 23",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand24",
"title": "Run quick command 24",
"category": "EditWithShell"
},
{
"command": "editWithShell.runQuickCommand25",
"title": "Run quick command 25",
"category": "EditWithShell"
}
],
"configuration": {
Expand Down Expand Up @@ -106,6 +226,86 @@
"description": "ID of a favorite command triggered by quick command 5",
"type": "string"
},
"editWithShell.quickCommand6": {
"description": "ID of a favorite command triggered by quick command 6",
"type": "string"
},
"editWithShell.quickCommand7": {
"description": "ID of a favorite command triggered by quick command 7",
"type": "string"
},
"editWithShell.quickCommand8": {
"description": "ID of a favorite command triggered by quick command 8",
"type": "string"
},
"editWithShell.quickCommand9": {
"description": "ID of a favorite command triggered by quick command 9",
"type": "string"
},
"editWithShell.quickCommand10": {
"description": "ID of a favorite command triggered by quick command 10",
"type": "string"
},
"editWithShell.quickCommand11": {
"description": "ID of a favorite command triggered by quick command 11",
"type": "string"
},
"editWithShell.quickCommand12": {
"description": "ID of a favorite command triggered by quick command 12",
"type": "string"
},
"editWithShell.quickCommand13": {
"description": "ID of a favorite command triggered by quick command 13",
"type": "string"
},
"editWithShell.quickCommand14": {
"description": "ID of a favorite command triggered by quick command 14",
"type": "string"
},
"editWithShell.quickCommand15": {
"description": "ID of a favorite command triggered by quick command 15",
"type": "string"
},
"editWithShell.quickCommand16": {
"description": "ID of a favorite command triggered by quick command 16",
"type": "string"
},
"editWithShell.quickCommand17": {
"description": "ID of a favorite command triggered by quick command 17",
"type": "string"
},
"editWithShell.quickCommand18": {
"description": "ID of a favorite command triggered by quick command 18",
"type": "string"
},
"editWithShell.quickCommand19": {
"description": "ID of a favorite command triggered by quick command 19",
"type": "string"
},
"editWithShell.quickCommand20": {
"description": "ID of a favorite command triggered by quick command 20",
"type": "string"
},
"editWithShell.quickCommand21": {
"description": "ID of a favorite command triggered by quick command 21",
"type": "string"
},
"editWithShell.quickCommand22": {
"description": "ID of a favorite command triggered by quick command 22",
"type": "string"
},
"editWithShell.quickCommand23": {
"description": "ID of a favorite command triggered by quick command 23",
"type": "string"
},
"editWithShell.quickCommand24": {
"description": "ID of a favorite command triggered by quick command 24",
"type": "string"
},
"editWithShell.quickCommand25": {
"description": "ID of a favorite command triggered by quick command 25",
"type": "string"
},
"editWithShell.favoriteCommands": {
"description": "Commands that can be activated by quick commands",
"type": "array",
Expand All @@ -117,15 +317,27 @@
},
"command": {
"type": "string"
},
"processEntireTextIfNoneSelected": {
"type": "boolean"
}
},
"required": [
"id",
"command"
]
},
"default": []
},
"editWithShell.clearFavoriteCommands": {
"description": "When clearing command history, clear also favorite commands",
"type": "boolean",
"default": true
},
"editWithShell.promptModifyCommand": {
"description": "Display a prompt to modify the selected command",
"type": "boolean",
"default": true
},
"editWithShell.processEntireTextIfNoneSelected": {
"description": "Pipe the entire text to the shell command if no text is selected",
"type": "boolean",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/app-integrator-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AppIntegratorFactory {
private get runCommand() {
return this.wrapCommand(new RunInputCommand(
this.shellCommandService,
new CommandReader(this.historyStore, vscode.window),
new CommandReader(this.historyStore, vscode.window, this.workspaceAdapter),
this.historyStore,
this.workspaceAdapter
));
Expand Down Expand Up @@ -61,7 +61,7 @@ export class AppIntegratorFactory {
}

private get historyStore() {
this.cache.historyStore = this.cache.historyStore || new HistoryStore();
this.cache.historyStore = this.cache.historyStore || new HistoryStore(this.workspaceAdapter);
return this.cache.historyStore;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/app-integrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class AppIntegrator {
id: `${EXTENSION_NAME}.runCommand`,
command: this.runCommand
},
...[1, 2, 3, 4, 5].map(n => ({
...Array.from({length: 25}, (_, i) => i + 1).map(n => ({
id: `${EXTENSION_NAME}.runQuickCommand${n}`,
command: this.createQuickCommand(n)
}))
Expand Down
Loading