Created
August 23, 2022 06:27
-
-
Save GaurangTandon/f5663544c93b9df39e86067034913a7c to your computer and use it in GitHub Desktop.
for use with vscode macros extension
This file contains 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 characters
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('-'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment