Skip to content

Commit

Permalink
add a random tab command
Browse files Browse the repository at this point in the history
  • Loading branch information
hippietrail committed Jan 25, 2025
1 parent 49996fe commit e53645e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
37 changes: 37 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"randomFile.extensions": [

".htm",
".html",
".md",
".txt",
".asm",
".s",
".c",
".cpp",
".h",
".cs",
".dart",
".go",
".jai",
".java",
".js",
".jsx",
".ts",
".tsx",
".kt",
".lua",
".odin",
".php",
".pl",
".py",
".rb",
".rs",
".sh",
".swift",
".zig"
],
"randomFile.excludeDirs": [
"node_modules"
]
}
23 changes: 23 additions & 0 deletions out/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,31 @@ async function randomFile() {
}
}

async function randomTab() {
try {
const tabGroups = vscode.window.tabGroups;
const numTabGroups = tabGroups.all.length;

if (numTabGroups > 0) {
const g = Math.floor(Math.random() * numTabGroups);

const tabGroup = tabGroups.all[g];
const tabs = tabGroup.tabs;
const numTabs = tabs.length;

if (numTabs > 0) {
await vscode.window.showTextDocument(tabs[Math.floor(Math.random() * numTabs)].input, { viewColumn: tabGroup.viewColumn });
}
}
} catch (error) {
console.error(error);
vscode.window.showErrorMessage('An error occurred while trying to switch to a random tab.');
}
}

exports.activate = function (context) {
context.subscriptions.push(vscode.commands.registerCommand('extension.randomFile', randomFile));
context.subscriptions.push(vscode.commands.registerCommand('extension.randomTab', randomTab));
};

exports.deactivate = function () { }

0 comments on commit e53645e

Please sign in to comment.