Skip to content

Instantly share code, notes, and snippets.

@FishingHacks
Created March 28, 2023 10:00
Show Gist options
  • Save FishingHacks/3721fd2a8b6cedc188bbdef31187ba2a to your computer and use it in GitHub Desktop.
Save FishingHacks/3721fd2a8b6cedc188bbdef31187ba2a to your computer and use it in GitHub Desktop.
import { join } from 'path';
import './globals';
export async function fileExplorer(dir: string) {
while (true) {
if (!(await fs.isDir(dir))) break;
const entries = await fs.listDir(dir);
entries.unshift('..');
const choice = await arg(
dir.startsWith(getHomePath())
? dir.replace(getHomePath(), '~')
: dir,
entries
);
dir = join(dir, choice);
}
return dir;
}
export async function dirExplorer(dir: string) {
while (true) {
const _entries = await fs.listDir(dir);
const entries: string[] = [];
for (const f of _entries) if (await fs.isDir(join(dir, f))) entries.push(f);
entries.unshift('..');
entries.unshift('\\select this directory/');
const choice = await arg(
dir.startsWith(getHomePath())
? dir.replace(getHomePath(), '~')
: dir,
entries
);
if (choice === '\\select this directory/') return dir;
dir = join(dir, choice);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment