Skip to content

Instantly share code, notes, and snippets.

@OmerFarukOruc
Created January 28, 2026 10:02
Show Gist options
  • Select an option

  • Save OmerFarukOruc/b2fae6f8f30e0accf037ba27f297b479 to your computer and use it in GitHub Desktop.

Select an option

Save OmerFarukOruc/b2fae6f8f30e0accf037ba27f297b479 to your computer and use it in GitHub Desktop.
OpenCode Custom Tool: fd (fast file finder) - Integrate sharkdp/fd into OpenCode for faster file searching with regex support
import { tool } from "@opencode-ai/plugin";
export default tool({
description:
"Fast file finder (fd) - faster than find/glob, respects .gitignore, supports regex. Use for finding files by name or pattern.",
args: {
pattern: tool.schema
.string()
.optional()
.describe(
"Search pattern (regex). Examples: 'component', '^test_.*\\.py$'",
),
path: tool.schema.string().optional().describe("Directory to search in"),
extension: tool.schema
.string()
.optional()
.describe("Filter by extension (e.g., 'ts', 'py')"),
type: tool.schema
.enum(["f", "d", "l", "x"])
.optional()
.describe("f=file, d=directory, l=symlink, x=executable"),
hidden: tool.schema.boolean().optional().describe("Include hidden files"),
no_ignore: tool.schema
.boolean()
.optional()
.describe("Don't respect .gitignore"),
max_depth: tool.schema.number().optional().describe("Max directory depth"),
},
async execute(args, context) {
const parts: string[] = ["fd"];
if (args.hidden) parts.push("--hidden");
if (args.no_ignore) parts.push("--no-ignore");
if (args.extension) parts.push(`-e ${args.extension}`);
if (args.type) parts.push(`-t ${args.type}`);
if (args.max_depth) parts.push(`--max-depth ${args.max_depth}`);
parts.push(`'${args.pattern || "."}'`);
parts.push(`'${args.path || context.directory}'`);
const cmd = parts.join(" ");
try {
const result = await Bun.$`sh -c ${cmd}`.text();
return result.trim() || "No files found";
} catch (error: unknown) {
const err = error as {
exitCode?: number;
stderr?: { toString(): string };
};
if (err.exitCode === 1) return "No files found";
return `Error: ${err.stderr?.toString() || error}\nCommand: ${cmd}`;
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment