Skip to content

Instantly share code, notes, and snippets.

@GaurangTandon
Last active February 11, 2025 10:17

Revisions

  1. GaurangTandon revised this gist Feb 11, 2025. 1 changed file with 19 additions and 4 deletions.
    23 changes: 19 additions & 4 deletions filemacro.js
    Original 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("G:/textblaze/bono/chrome_extension/src/js/contentScript.js")
    func: () => {
    openFile("chrome_extension/src/js/contentScript.js")
    }
    },
    OpenReplacement: {
    no: 2,
    func: () => openFile("G:/textblaze/bono/chrome_extension/src/js/replacement.js")
    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 document = await vscode.workspace.openTextDocument(filename);
    const editor = await vscode.window.showTextDocument(document);
    const path = pathModule.join(workspaceRoot, filename);
    const document = await vscode.workspace.openTextDocument(path);
    await vscode.window.showTextDocument(document);
    }

    // logging
  2. GaurangTandon created this gist Aug 23, 2022.
    51 changes: 51 additions & 0 deletions filemacro.js
    Original 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('-');
    }
    }
    }