Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions crates/bashkit/src/builtins/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,19 @@ struct FindOptions {
name_pattern: Option<String>,
type_filter: Option<char>,
max_depth: Option<usize>,
// -exec is parsed but acts like -print (builtin can't invoke interpreter)
// WTF: exec needs interpreter access; for now just collect paths so scripts don't error
has_exec: bool,
}

/// The find builtin - search for files.
///
/// Usage: find [PATH...] [-name PATTERN] [-type TYPE] [-maxdepth N]
/// Usage: find [PATH...] [-name PATTERN] [-type TYPE] [-maxdepth N] [-exec CMD {} \;]
///
/// Options:
/// -name PATTERN Match filename against PATTERN (supports * and ?)
/// -type TYPE Match file type: f (file), d (directory), l (link)
/// -maxdepth N Descend at most N levels
/// -print Print matching paths (default)
/// -name PATTERN Match filename against PATTERN (supports * and ?)
/// -type TYPE Match file type: f (file), d (directory), l (link)
/// -maxdepth N Descend at most N levels
/// -print Print matching paths (default)
/// -exec CMD {} \; Execute CMD for each match ({} = path)
/// -exec CMD {} + Execute CMD once with all matches
pub struct Find;

#[async_trait]
Expand All @@ -319,7 +318,6 @@ impl Builtin for Find {
name_pattern: None,
type_filter: None,
max_depth: None,
has_exec: false,
};

// Parse arguments
Expand Down Expand Up @@ -375,9 +373,8 @@ impl Builtin for Find {
// Default action, ignore
}
"-exec" | "-execdir" => {
// Parse -exec command {} \; or {} +
// Skip all args until we find \; or +
opts.has_exec = true;
// -exec is handled at interpreter level (execute_find);
// skip args here for fallback path
i += 1;
while i < ctx.args.len() {
let a = &ctx.args[i];
Expand Down Expand Up @@ -501,7 +498,7 @@ fn find_recursive<'a>(
}

/// Simple glob pattern matching for find -name
fn glob_match(value: &str, pattern: &str) -> bool {
pub(crate) fn glob_match(value: &str, pattern: &str) -> bool {
let mut value_chars = value.chars().peekable();
let mut pattern_chars = pattern.chars().peekable();

Expand Down
1 change: 1 addition & 0 deletions crates/bashkit/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub use headtail::{Head, Tail};
pub use hextools::{Hexdump, Od, Xxd};
pub use inspect::{File, Less, Stat};
pub use jq::Jq;
pub(crate) use ls::glob_match;
pub use ls::{Find, Ls, Rmdir};
pub use navigation::{Cd, Pwd};
pub use nl::Nl;
Expand Down
Loading
Loading