Skip to content

Commit

Permalink
add --ignore, --match options
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-ward committed Jan 6, 2025
1 parent ab8ec76 commit 85be120
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ All notable changes to this project will be documented in this file.
- almost all option (-A)
- full path option (-F)
- relative time option (-T)
- mime type (-M)
- entry number (-#)
- mime type option (-M)
- entry number option (-#)
- --before, --after TIME options
- --ignore=GLOB, --match=GLOB options

## [2024.6]
### Added
Expand Down
14 changes: 14 additions & 0 deletions lsv/filter.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ fn filter(entries []Entry, options Options) []Entry {
filtered = filtered.filter(it.file)
}

if options.glob_ignore.len > 0 {
for glob in options.glob_ignore.split('|') {
filtered = filtered.filter(!it.name.match_glob(glob))
}
}

if options.glob_match.len > 0 {
mut matched := []Entry{}
for glob in options.glob_match.split('|') {
matched << filtered.filter(it.name.match_glob(glob))
}
filtered = matched.clone()
}

filtered = filter_time(filtered, options.time_before_modified, .before_modified)
filtered = filter_time(filtered, options.time_before_modified, .before_accessed)
filtered = filter_time(filtered, options.time_before_modified, .before_changed)
Expand Down
7 changes: 7 additions & 0 deletions lsv/options.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct Options {
all bool
almost_all bool
dirs_first bool
glob_ignore string
glob_match string
only_dirs bool
only_files bool
recursion_depth int
Expand Down Expand Up @@ -127,6 +129,9 @@ fn parse_args(args []string) Options {
time_before_changed := fp.string('before-change', 0, '', 'before change time <string>\n\n' +
'${flag.space}where time <string> is an ISO 8601 format.\n' +
'${flag.space}See: https://ijmacd.github.io/rfc3339-iso8601\n')

glob_ignore := fp.string('ignore', 0, '', 'ignore glob patterns (pipe-separated)')
glob_match := fp.string('match', 0, '', 'match glob patterns (pipe-separated)\n')
sort_ignore_case := fp.bool('ignore-case', 0, false, 'ignore case when sorting\n\nLong Listing Options:')

blocked_output := fp.bool('', `b`, false, 'blank line every 5 rows')
Expand Down Expand Up @@ -179,6 +184,8 @@ fn parse_args(args []string) Options {
dirs_first: dirs_first
files: if files == [] { current_dir } else { files }
full_path: full_path
glob_ignore: glob_ignore
glob_match: glob_match
header: header
icons: icons
index: index
Expand Down

0 comments on commit 85be120

Please sign in to comment.