Skip to content

Commit

Permalink
Store multiple -contains arguments (OR default).
Browse files Browse the repository at this point in the history
Allow multiple occurrences of the -contains argument
to be stored in a list. Previously, only the last occurrence was
considered. Additionally, the behavior has been modified to default to
OR logic, meaning that if multiple -contains arguments are provided,
entries matching any of them will be included in the results.
  • Loading branch information
eigenric committed May 9, 2024
1 parent 0aefdb3 commit edff5f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions jrnl/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
reading.add_argument(
"-contains",
dest="contains",
action="append",
metavar="TEXT",
help="Show entries containing specific text (put quotes around text with "
"spaces)",
Expand Down
11 changes: 7 additions & 4 deletions jrnl/journals/Journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def filter(
exclude_starred=False,
exclude_tagged=False,
strict=False,
contains=None,
contains=[],
exclude=[],
):
"""Removes all entries from the journal that don't match the filter.
Expand Down Expand Up @@ -276,7 +276,7 @@ def excluded(tags):
return 0 < len([tag for tag in tags if tag in excluded_tags])

if contains:
contains_lower = contains.casefold()
contains_lower = [substring.casefold() for substring in contains]

# Create datetime object for comparison below
# this approach allows various formats
Expand All @@ -298,8 +298,11 @@ def excluded(tags):
and (
not contains
or (
contains_lower in entry.title.casefold()
or contains_lower in entry.body.casefold()
any(
substring in entry.title.casefold()
or substring in entry.body.casefold()
for substring in contains_lower
)
)
)
]
Expand Down

0 comments on commit edff5f8

Please sign in to comment.