Skip to content

Commit

Permalink
feat(set): implement nullglob option (#279)
Browse files Browse the repository at this point in the history
Also adds tests for nullglob and noglob.
  • Loading branch information
reubeno authored Nov 29, 2024
1 parent 7dcc411 commit c372508
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion brush-core/src/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl<'a> WordExpander<'a> {
)
.unwrap_or_default();

if expansions.is_empty() {
if expansions.is_empty() && !self.shell.options.expand_non_matching_patterns_to_null {
vec![String::from(field)]
} else {
expansions
Expand Down
15 changes: 15 additions & 0 deletions brush-shell/tests/cases/patterns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ cases:
- name: "Single file expansion"
stdin: "echo file1.txt"

- name: "Expansion with noglob"
test_files:
- path: "file1.txt"
- path: "file2.txt"
stdin: |
set -f
echo "*.txt:" *.txt
- name: "Multiple file expansion"
test_files:
- path: "file1.txt"
Expand All @@ -26,6 +34,13 @@ cases:
- path: "file1.txt"
stdin: "echo *.jpg"

- name: "Expansion with no matches + nullglob"
test_files:
- path: "file1.txt"
stdin: |
shopt -s nullglob
echo "*.jpg:" *.jpg
- name: "Expansion with special characters"
test_files:
- path: "file1.txt"
Expand Down

0 comments on commit c372508

Please sign in to comment.