overhaul file search and support @ mentioning directories

This commit is contained in:
Dax Raad
2025-10-01 03:37:01 -04:00
parent fe45a76c55
commit 6e19200fca
10 changed files with 132 additions and 27 deletions

View File

@@ -2,6 +2,22 @@ import { File } from "../../../file"
import { bootstrap } from "../../bootstrap"
import { cmd } from "../cmd"
const FileSearchCommand = cmd({
command: "search <query>",
builder: (yargs) =>
yargs.positional("query", {
type: "string",
demandOption: true,
description: "Search query",
}),
async handler(args) {
await bootstrap(process.cwd(), async () => {
const results = await File.search({ query: args.query })
console.log(results.join("\n"))
})
},
})
const FileReadCommand = cmd({
command: "read <path>",
builder: (yargs) =>
@@ -48,6 +64,11 @@ const FileListCommand = cmd({
export const FileCommand = cmd({
command: "file",
builder: (yargs) =>
yargs.command(FileReadCommand).command(FileStatusCommand).command(FileListCommand).demandCommand(),
yargs
.command(FileReadCommand)
.command(FileStatusCommand)
.command(FileListCommand)
.command(FileSearchCommand)
.demandCommand(),
async handler() {},
})

View File

@@ -40,12 +40,14 @@ const FilesCommand = cmd({
}),
async handler(args) {
await bootstrap(process.cwd(), async () => {
const files = await Ripgrep.files({
const files: string[] = []
for await (const file of Ripgrep.files({
cwd: Instance.directory,
query: args.query,
glob: args.glob ? [args.glob] : undefined,
limit: args.limit,
})
})) {
files.push(file)
if (args.limit && files.length >= args.limit) break
}
console.log(files.join("\n"))
})
},