From 0cafe7629d4fea048ab44b733d0849f9e8d6fd51 Mon Sep 17 00:00:00 2001 From: dmarakom6 Date: Thu, 18 Feb 2021 09:13:24 +0200 Subject: [PATCH] organize files for "listnotes -d" --- util/listnotes/d/d.py | 61 +++++++++++++++++++++++++++++++++++++ util/listnotes/d/d.sh | 9 ++++++ util/listnotes/d/display.py | 11 +++++++ util/listnotes/d/dmain.py | 9 ++++++ 4 files changed, 90 insertions(+) create mode 100644 util/listnotes/d/d.py create mode 100644 util/listnotes/d/d.sh create mode 100644 util/listnotes/d/display.py create mode 100644 util/listnotes/d/dmain.py diff --git a/util/listnotes/d/d.py b/util/listnotes/d/d.py new file mode 100644 index 0000000..69a714d --- /dev/null +++ b/util/listnotes/d/d.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +#shellnotes - d.py +#(C) Dimitris Marakomihelakis +#Released under the "All rights reserved" category. See the RIGHTS.txt file +#in /docs/github/ for its full text. + +import display +import subprocess +import sys +import os +import time +from os import listdir +from os.path import isfile, join +from pathlib import Path + + +class cd: + """Context manager for changing the current working directory""" + + def __init__(self, newPath): + self.newPath = os.path.expanduser(newPath) + + def __enter__(self): + self.savedPath = os.getcwd() + os.chdir(self.newPath) + + def __exit__(self, etype, value, traceback): + os.chdir(self.savedPath) + + +folder = "cat ~/.shellnotes/util/sd/sd-input3.txt" +files = "eval echo $(cat ~/.shellnotes/util/sd/sd-input3.txt) | xargs ls | wc -l" + + +os.system(folder + "> ~/.shellnotes/util/listnotes/output/dir.txt 2> ~/.shellnotes/util/listnotes/output/direrr.txt") +os.system(files + "> ~/.shellnotes/util/listnotes/output/files.txt 2> ~/.shellnotes/util/listnotes/output/fileserr.txt" ) + +with cd("~/.shellnotes/util/listnotes/output"): + with open("files.txt", 'r') as f: + files = f.read() + with open("dir.txt", 'r') as d: + folder = d.read() + +files = files.strip() +folder = folder.strip() + +home = str(Path.home()) +folder = folder.replace('~', home) + +print(f"\nFound {files} notes in {folder}:\n") + +onlyfiles = [f for f in listdir(folder) if isfile(join(folder, f))] +for file in onlyfiles: + display.underlined(file) + path = folder + '/' + file + listnotes = "head" + " -n" + " 5" + " " + path + "\n" + str(os.system(listnotes + "> ~/.shellnotes/util/listnotes/output/listnotes.txt")) + print() +print("If your note is not shown, try 'findmisplacednote ' to locate it.") + diff --git a/util/listnotes/d/d.sh b/util/listnotes/d/d.sh new file mode 100644 index 0000000..4059770 --- /dev/null +++ b/util/listnotes/d/d.sh @@ -0,0 +1,9 @@ +:<<'info' +shellnotes - d.sh +(C) Dimitris Marakomihelakis +Released under the "All rights reserved" category. See the RIGHTS.txt file +in /docs/github/ for its full text. +info + +chmod +x ~/.shellnotes/util/listnotes/d.py +python3 ~/.shellnotes/util/listnotes/d.py \ No newline at end of file diff --git a/util/listnotes/d/display.py b/util/listnotes/d/display.py new file mode 100644 index 0000000..df64522 --- /dev/null +++ b/util/listnotes/d/display.py @@ -0,0 +1,11 @@ +def underlined(text, symbol = '-'): + print() + print(text) + print(symbol * len(text)) + +def bordered(text, symbol = '*'): + print() + print(symbol * (len(text) + 4)) + print(symbol, text, symbol) + print(symbol * (len(text) + 4)) + print() \ No newline at end of file diff --git a/util/listnotes/d/dmain.py b/util/listnotes/d/dmain.py new file mode 100644 index 0000000..7f0ed2c --- /dev/null +++ b/util/listnotes/d/dmain.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + +#shellnotes - dmain.py +#(C) Dimitris Marakomihelakis +#Released under the "All rights reserved" category. See the RIGHTS.txt file +#in /docs/github/ for its full text. + +from d import d +