Skip to content

Commit

Permalink
match shell scripts by file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
blmaier committed Mar 6, 2024
1 parent be921b9 commit 083ca16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/walk_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,24 @@ fn entry_is_file(entry: &ignore::DirEntry) -> bool {

fn entry_is_shellscript(entry: &ignore::DirEntry) -> bool {
if entry_is_file(entry) {
match file_format::FileFormat::from_file(entry.path()) {
Ok(fmt) => match fmt {
file_format::FileFormat::ShellScript => true,
_ => false,
match entry.path().extension() {
Some(ext) => match ext.to_str() {
Some("sh") | Some("bash") | Some("zsh") | Some("bats") => true,
Some(_) | None => entry_shellcript_format(entry),
},
Err(err) => panic!("File Format Error: {}", err),
None => entry_shellcript_format(entry),
}
} else {
false
}
}

fn entry_shellcript_format(entry: &ignore::DirEntry) -> bool {
match file_format::FileFormat::from_file(entry.path()) {
Ok(fmt) => match fmt {
file_format::FileFormat::ShellScript => true,
_ => false,
},
Err(err) => panic!("File Format Error: {}", err),
}
}
10 changes: 10 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ fn compare_file(path: &str) {
fn one_file() {
compare_file("boringssl/crypto/lhash/make_macros.sh");
}

#[test]
fn find_by_shebang() {
compare_file("pixelb-scripts/scripts/errno");
}

#[test]
fn find_by_extension() {
compare_file("shell/shflags/shflags_issue_28_test.sh");
}

0 comments on commit 083ca16

Please sign in to comment.