-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4b54354
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
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
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. |
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
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 () { } |
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
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" | ||
} |