Skip to content

Commit 56c1996

Browse files
chuckhendopatbenatar
authored andcommitted
adds brace expansion
1 parent 3a59cd7 commit 56c1996

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
"root"
6262
],
6363
"description": "Convenience options display at the top of the list. Control which ones you see and in what order."
64+
},
65+
"advancedNewFile.expandBraces": {
66+
"type": "boolean",
67+
"default": false,
68+
"description": "Whether braces should be expanded to multiple paths (such as {test1,test2}.js creating two files, test1.js and test2.js"
6469
}
6570
}
6671
}
@@ -97,6 +102,7 @@
97102
"ovsx": "0.1.0-next.a9154dc"
98103
},
99104
"dependencies": {
105+
"braces": "^3.0.2",
100106
"gitignore-to-glob": "github:patbenatar/gitignore-to-glob",
101107
"lodash": "^4.17.13",
102108
"glob": "^7.1.1",

src/extension.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as gitignoreToGlob from 'gitignore-to-glob';
88
import { sync as globSync } from 'glob';
99
import * as Cache from 'vscode-cache';
1010
import { QuickPickItem, ViewColumn } from 'vscode';
11+
import * as braces from 'braces';
1112

1213
export interface FSLocation {
1314
relative: string;
@@ -188,6 +189,17 @@ export function currentEditorPath(): string {
188189
return path.dirname(activeEditor.document.fileName);
189190
}
190191

192+
export function expandBraces(absolutePath: string): string[] {
193+
const shouldExpandBraces =
194+
vscode.workspace.getConfiguration('advancedNewFile').get('expandBraces');
195+
196+
if (!shouldExpandBraces) {
197+
return [absolutePath];
198+
}
199+
200+
return braces.expand(absolutePath);
201+
}
202+
191203
export function createFileOrFolder(absolutePath: string): void {
192204
let directoryToFile = path.dirname(absolutePath);
193205

@@ -213,7 +225,7 @@ export async function openFile(absolutePath: string): Promise<void> {
213225
const textDocument = await vscode.workspace.openTextDocument(absolutePath);
214226

215227
if (textDocument) {
216-
vscode.window.showTextDocument(textDocument, ViewColumn.Active);
228+
vscode.window.showTextDocument(textDocument, { preview: false });
217229
}
218230
}
219231
}
@@ -360,8 +372,11 @@ export async function command(context: vscode.ExtensionContext) {
360372
const newFileInput = await showInputBox(dir);
361373
if (!newFileInput) return;
362374

363-
createFileOrFolder(newFileInput);
364-
await openFile(newFileInput);
375+
const newFileArray = expandBraces(newFileInput);
376+
for (let newFile of newFileArray) {
377+
createFileOrFolder(newFile);
378+
await openFile(newFile);
379+
}
365380
} else {
366381
await vscode.window.showErrorMessage(
367382
'It doesn\'t look like you have a folder opened in your workspace. ' +

0 commit comments

Comments
 (0)