From 5fe0a4b5fd33ee365a3396d4210f031aa8610700 Mon Sep 17 00:00:00 2001 From: dmarakom6 Date: Sat, 3 Jul 2021 10:15:58 +0300 Subject: [PATCH] Apply line-buffering method with print() --- util/notegrep.sh | 7 ++++++- util/notegrep/m.py | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/util/notegrep.sh b/util/notegrep.sh index e27292e..2b639a9 100644 --- a/util/notegrep.sh +++ b/util/notegrep.sh @@ -138,7 +138,12 @@ function notegrep() { ;; -m | --multiple ) cd ~ - python3 ~/.shellnotes/util/notegrep/m.py $regex $notename + if [ "$(python3 ~/.shellnotes/util/notegrep/m.py $regex $notename | wc -l)" -ge 20 ]; then + python3 ~/.shellnotes/util/notegrep/m.py $regex $notename | less -R + else + python3 ~/.shellnotes/util/notegrep/m.py $regex $notename + fi + cd $DIR ;; *) diff --git a/util/notegrep/m.py b/util/notegrep/m.py index 38f931a..2bd368f 100644 --- a/util/notegrep/m.py +++ b/util/notegrep/m.py @@ -29,8 +29,8 @@ class Multi(): for file in self.files: try: if file == "": return 0 - print("\n"+file if path.exists('Notes/'+file) else f"\n{file} (not found):\n-") - print("=" * len(file) if path.exists('Notes/'+file) else "") + print("\n"+file if path.exists('Notes/'+file) else f"\n{file} (not found):\n-", flush=True) + print("=" * len(file) if path.exists('Notes/'+file) else "", flush=True) for pattern in self.patterns: if pattern == "": return 0 @@ -39,6 +39,7 @@ class Multi(): if re.search(pattern, line): out = os.system(f"""echo -n "'{pattern}'": && grep -n --color=always {pattern} Notes/{file}""") #bug: pattern is generated multiple times + except FileNotFoundError: pass