Skip to content

Instantly share code, notes, and snippets.

@GaurangTandon
Created August 23, 2022 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GaurangTandon/f5663544c93b9df39e86067034913a7c to your computer and use it in GitHub Desktop.
Save GaurangTandon/f5663544c93b9df39e86067034913a7c to your computer and use it in GitHub Desktop.
for use with vscode macros extension
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