Last active
February 11, 2025 10:17
Revisions
-
GaurangTandon revised this gist
Feb 11, 2025 . 1 changed file with 19 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,20 @@ const vscode = require('vscode'); const pathModule = require('path'); const gitExt = vscode.extensions.getExtension('vscode.git')?.exports; const gitAPI = gitExt.getAPI(1); module.exports.macroCommands = { OpenContentScript: { no: 1, func: () => { openFile("chrome_extension/src/js/contentScript.js") } }, OpenReplacement: { no: 2, func: () => { openFile("chrome_extension/src/js/replacement.js") } }, CheckoutMain: { no: 3, @@ -21,9 +26,19 @@ module.exports.macroCommands = { } }; function getWorkspaceRoot() { const workspaceFolders = vscode.workspace.workspaceFolders; if (workspaceFolders && workspaceFolders.length > 0) { return workspaceFolders[0].uri.fsPath; // Root path of the first workspace folder } return '/Users/blazegt/bono/'; // No workspace opened } const workspaceRoot = getWorkspaceRoot(); async function openFile(filename) { const path = pathModule.join(workspaceRoot, filename); const document = await vscode.workspace.openTextDocument(path); await vscode.window.showTextDocument(document); } // logging -
GaurangTandon created this gist
Aug 23, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ const vscode = require('vscode'); const gitExt = vscode.extensions.getExtension('vscode.git')?.exports; const gitAPI = gitExt.getAPI(1); module.exports.macroCommands = { OpenContentScript: { no: 1, func: () => openFile("G:/textblaze/bono/chrome_extension/src/js/contentScript.js") }, OpenReplacement: { no: 2, func: () => openFile("G:/textblaze/bono/chrome_extension/src/js/replacement.js") }, CheckoutMain: { no: 3, func: () => checkoutToMain() }, CheckoutPrevious: { no: 4, func: () => checkoutToPreviousBranch() } }; async function openFile(filename) { const document = await vscode.workspace.openTextDocument(filename); const editor = await vscode.window.showTextDocument(document); } // logging // let orange = vscode.window.createOutputChannel("Orange" + Math.random()); // orange.appendLine("I am a banana."); // orange.show(); // git extension developer api reference // https://stackoverflow.com/questions/59442180/vs-code-git-extension-api async function checkoutToMain() { for (const repo of gitAPI.repositories) { if (repo.rootUri.toString().includes('bono')) { repo.checkout('main'); } } } async function checkoutToPreviousBranch() { for (const repo of gitAPI.repositories) { if (repo.rootUri.toString().includes('bono')) { repo.checkout('-'); } } }