diff --git a/jrnl/args.py b/jrnl/args.py index 53a77462..43685182 100644 --- a/jrnl/args.py +++ b/jrnl/args.py @@ -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)", diff --git a/jrnl/journals/Journal.py b/jrnl/journals/Journal.py index d1054814..27b8505c 100644 --- a/jrnl/journals/Journal.py +++ b/jrnl/journals/Journal.py @@ -246,7 +246,7 @@ class Journal: exclude_starred=False, exclude_tagged=False, strict=False, - contains=None, + contains=[], exclude=[], ): """Removes all entries from the journal that don't match the filter. @@ -276,7 +276,7 @@ class Journal: 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 @@ -298,8 +298,11 @@ class Journal: 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 + ) ) ) ]