Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hippietrail committed Jan 17, 2025
0 parents commit 4b54354
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Random File Extension for Visual Studio Code

## Overview
The **Random File** extension for Visual Studio Code allows you to quickly open a random file from the current workspace. Can be quite handy for exploring new projects.

## Features
- Open a random file from your workspace.
- Filter files by extensions.
- Excludes files in the `node_modules` directory.

## Usage
- After installing the extension, you can trigger the command by:
- Opening the Command Palette (`Cmd+Shift+P` on macOS, `Ctrl+Shift+P` on Windows) and typing `Open a random File`.

## Configuration
You can customize the file extensions that the extension considers by adding the following configuration to your `settings.json`:

```json
"randomFile.extensions": [".md", ".txt"]
```

## License
This project is licensed under the MIT License.
33 changes: 33 additions & 0 deletions out/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";

const vscode = require('vscode');

async function randomFile() {
try {
const allFiles = await vscode.workspace.findFiles('**/*');
const exts = vscode.workspace.getConfiguration().get('randomFile.extensions', []);

const sift = (ele) => {
if (ele.path.includes('node_modules')) return false;
const ext = ele.path.substring(ele.path.lastIndexOf('.'));
if (!exts.includes(ext)) return false;
if (exts.length === 0) return true;
return exts.some(path => ele.path.includes(path));
};

const eligible = allFiles.filter(sift);

if (eligible.length > 0) {
await vscode.window.showTextDocument(await vscode.workspace.openTextDocument(eligible[Math.floor(Math.random() * eligible.length)]));
}
} catch (error) {
console.error(error);
vscode.window.showErrorMessage('An error occurred while trying to open a random file.');
}
}

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

exports.deactivate = function () { }
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"contributes": {
"commands": [
{
"command": "extension.randomFile",
"title": "Open a random File"
}
],
"configuration": {
"title": "Open a random file",
"properties": {
"randomFile.extensions": {
"type": "array",
"default": [ ".md", ".txt" ],
"description": "Only choose files with these extensions"
}
}
}
},
"engines": {
"vscode": "^1.7.5"
},
"main": "./out/extension.js",
"name": "random-file",
"publisher": "hippietrail",
"version": "0.0.1"
}

0 comments on commit 4b54354

Please sign in to comment.