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

Added the option to give named configuration instead of only a default one #55

Open
wants to merge 3 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
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"extends": ["plugin:prettier/recommended"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
}
}
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,55 @@ Simply configure your VSCode settings JSON file to look something like this:
]
```

Or named configurations that you can choose between:

```
"restoreTerminals.terminals": {
"dev": [
{
"splitTerminals": [
{
"name": "server",
"commands": ["npm i", "npm run dev"]
},
{
"name": "client",
"commands": ["npm run dev:client"]
}
]
},
{
"splitTerminals": [
{
"name": "worker",
"commands": ["npm-run-all --parallel redis tsc-watch-start worker"]
}
]
}
],
"test": [
{
"splitTerminals": [
{
"name": "test",
"commands": ["jest --watch"],
"shouldRunCommands": false
}
],
},
{
"splitTerminals": [
{
"name": "build & e2e",
"commands": ["npm run eslint", "npm run build", "npm run e2e"],
"shouldRunCommands": false
}
],
}
]
}
```

The outer array represents a integrated VSCode terminal window, and the `splitTerminals` array contains the information about how each terminal window should be split up.

You can also use a custom config file under. The file should be at `.vscode/restore-terminals.json` in any workspace you want. A sample config file is [here](https://github.com/EthanSK/restore-terminals-vscode/blob/master/sample-test-project/.vscode/restore-terminals.json). If this config file is present, Restore Terminals will try and load settings from it first, then use `settings.json` as a fallback.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 73 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,91 @@
"description": "If you find restore terminals glitching out, or running some commands in the wrong window, you might want to try increasing this number to further delay the processing of actions. If you find it taking too long to open the terminal windows, you can try reducing this number, be be cautious as if it's too fast it will bug out."
},
"restoreTerminals.terminals": {
"type": "array",
"items": {
"properties": {
"splitTerminals": {
"type": [
"array",
"object"
],
"oneOf": [
{
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"properties": {
"name": {
"type": "string",
"description": "The name to give the terminal window"
},
"icon": {
"type": "string",
"description": "The icon to give the terminal window"
},
"commands": {
"splitTerminals": {
"type": "array",
"description": "The shell commands to execute when this terminal opens.",
"items": {
"properties": {
"name": {
"type": "string",
"description": "The name to give the terminal window"
},
"icon": {
"type": "string",
"description": "The icon to give the terminal window"
},
"commands": {
"type": "array",
"description": "The shell commands to execute when this terminal opens.",
"items": {
"properties": {
"type": "string",
"description": "A shell command to run."
}
}
},
"shouldRunCommands": {
"type": "boolean",
"description": "Whether to actually run the commands in the terminal, or just paste them there."
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
}
},
{
"type": "array",
"items": {
"properties": {
"splitTerminals": {
"type": "array",
"items": {
"properties": {
"name": {
"type": "string",
"description": "The name to give the terminal window"
},
"icon": {
"type": "string",
"description": "A shell command to run."
"description": "The icon to give the terminal window"
},
"commands": {
"type": "array",
"description": "The shell commands to execute when this terminal opens.",
"items": {
"properties": {
"type": "string",
"description": "A shell command to run."
}
}
},
"shouldRunCommands": {
"type": "boolean",
"description": "Whether to actually run the commands in the terminal, or just paste them there."
}
}
},
"shouldRunCommands": {
"type": "boolean",
"description": "Whether to actually run the commands in the terminal, or just paste them there."
},
"additionalProperties": false
}
}
}
},
"additionalProperties": false
}
}
}
]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface TerminalWindow {
export interface Configuration {
keepExistingTerminalsOpen?: boolean;
artificialDelayMilliseconds?: number;
terminalWindows?: TerminalWindow[];
terminalWindows?: TerminalWindow[] | Map<string, TerminalWindow[]>;
runOnStartup?: boolean;
}

Expand Down
31 changes: 30 additions & 1 deletion src/restoreTerminals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MAX_TERM_CHECK_ATTEMPTS = 500; //this times SPLIT_TERM_CHECK_DELAY is the

export default async function restoreTerminals(configuration: Configuration) {
console.log("restoring terminals", configuration);
const {
let {
keepExistingTerminalsOpen,
artificialDelayMilliseconds,
terminalWindows,
Expand All @@ -19,6 +19,35 @@ export default async function restoreTerminals(configuration: Configuration) {
return;
}

if (!(terminalWindows instanceof Array) && terminalWindows !== null) {
terminalWindows = new Map(Object.entries(terminalWindows));
if (!terminalWindows.size) {
vscode.window.showInformationMessage(
"Empty terminal window configuration provided to restore terminals with."
); //this might be annoying
return;
}

if (terminalWindows.size > 1) {
const picked = await vscode.window.showQuickPick(
Array.from(terminalWindows.keys())
);
if (!picked) {
return;
}
terminalWindows = terminalWindows.get(picked) ?? [];
} else {
terminalWindows = Array.from(terminalWindows.values())[0];
}
}

if (!terminalWindows.length) {
vscode.window.showInformationMessage(
"Empty terminal window configuration provided to restore terminals with."
); //this might be annoying
return;
}

if (vscode.window.activeTerminal && !keepExistingTerminalsOpen) {
vscode.window.terminals.forEach((terminal) => {
//i think calling terminal.dispose before creating the new termials causes error because the terminal has disappeard and it fux up. we can do it after, and check that the terminal we are deleting is not in the list of terminals we just created
Expand Down