From 1e4d8c18c7ab59823920968ba6fe84d464598c6b Mon Sep 17 00:00:00 2001 From: James Downie Date: Mon, 30 Jun 2025 18:01:42 +1000 Subject: [PATCH 1/3] Lazy commit on scruffy. --- LICENSE | 2 ++ jdownie/repo/repo | 13 ++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index df76002..1f2351d 100644 --- a/LICENSE +++ b/LICENSE @@ -230,3 +230,5 @@ The hypothetical commands `show w' and `show c' should show the appropriate part You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . + + diff --git a/jdownie/repo/repo b/jdownie/repo/repo index 611ce5f..f61fcee 100755 --- a/jdownie/repo/repo +++ b/jdownie/repo/repo @@ -150,9 +150,8 @@ if __name__ == "__main__": prop = m.group(1) rest = m.group(2) if prop == "ab": - print("ding") - m2 = re.match(r"[+](\d+)\n[-](\d+)", rest) - p2 = "?" + m2 = re.match(r"[+](\d+)\s[-](\d+)", rest) + p2 = rest if m2: p2 = dict() p2["push"] = int(m2.group(1)) @@ -166,13 +165,13 @@ if __name__ == "__main__": else: n = n + 1 props["n"] = n - print(props) - dat[k] = n + dat[k] = props with open(cache_file, "wt") as fout: json.dump(dat, fout, indent = 2) for k in dat: - status = "-" if dat[k] == 0 else dat[k] - print("{0} {1}".format(str(status).rjust(3), k)) + status = "-" if dat[k]["n"] == 0 else dat[k]["n"] + print(f"{str(status).rjust(3)} {k}") + print(json.dumps(dat, indent = 2)) elif sys.argv[1] == "status": dat = dict() cache_file = filepath("status") From 02fc9cc8bf3fd49f792d0d775d580c9ca2077d6b Mon Sep 17 00:00:00 2001 From: James Downie Date: Mon, 30 Jun 2025 19:06:33 +1000 Subject: [PATCH 2/3] wrote an improved repo status output. --- jdownie/repo/repo | 49 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/jdownie/repo/repo b/jdownie/repo/repo index f61fcee..ccf30da 100755 --- a/jdownie/repo/repo +++ b/jdownie/repo/repo @@ -9,14 +9,37 @@ import json import time from pathlib import Path -def ind(): - print('\u2B06\uFE0F\u0031\uFE0F\u20E3') # ⬆️1️⃣ - print('\u2B07\uFE0F\u0032\uFE0F\u20E3') # ⬇️2️⃣ - for i in range(1, 6): - digit = str(i) - keycap = digit + '\uFE0F\u20E3' - print(f"\u2B06\uFE0F{keycap} Up {i}") - print(f"\u2B07\uFE0F{keycap} Down {i}") +def to_keycap(ch: str) -> str: + """ + Converts a single character (0-9, #, *) into a keycap emoji. + Returns the original character if not valid for keycaps. + """ + if ch in '0123456789#*': + return ch + '\uFE0F\u20E3' + else: + raise ValueError(f"Unsupported keycap character: {ch!r}") + +def indicators(props, ind = "tl"): + tl = "\U0001F7E2" + if props["ab"]["push"] + props["ab"]["pull"] > 0: + tl = "\U0001F7E1" + if props["n"] > 0: + tl = "\U0001F534" + unstaged = "\U0001F4DD" + up_keycap = "\U0001F53C" # "\u2B06\uFE0F" + down_keycap = "\U0001F53D" # "\u2B07\uFE0F" + status_digit = "#" if props["n"] > 9 else str(props["n"] % 10) + status_indicator = f"{to_keycap(status_digit)}{unstaged}" + push_digit = "#" if props["ab"]["push"] > 9 else str(props["ab"]["push"] % 10) + push_indicator = f"{to_keycap(push_digit)}{up_keycap}" + pull_digit = "#" if props["ab"]["pull"] > 9 else str(props["ab"]["pull"] % 10) + pull_indicator = f"{to_keycap(pull_digit)}{down_keycap}" + ret = "?" + if ind == "tl": + ret = f"{tl}" + if ind == "flags": + ret = f"{status_indicator} {push_indicator} {pull_indicator}" + return ret def rm(p): if os.path.exists(p): @@ -168,10 +191,14 @@ if __name__ == "__main__": dat[k] = props with open(cache_file, "wt") as fout: json.dump(dat, fout, indent = 2) + ml = 0 for k in dat: - status = "-" if dat[k]["n"] == 0 else dat[k]["n"] - print(f"{str(status).rjust(3)} {k}") - print(json.dumps(dat, indent = 2)) + ml = len(k) if len(k) > ml else ml + for k in dat: + tl = indicators(dat[k], "tl") + flags = indicators(dat[k], "flags") + print(f" {tl} {k.ljust(ml + 1)} {flags}") + # print(json.dumps(dat, indent = 2)) elif sys.argv[1] == "status": dat = dict() cache_file = filepath("status") From 2f3e08f58c1c1679a5482b85456840c65c12902a Mon Sep 17 00:00:00 2001 From: James Downie Date: Mon, 30 Jun 2025 19:08:40 +1000 Subject: [PATCH 3/3] switched the new test output in to replace the old status output --- jdownie/repo/repo | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/jdownie/repo/repo b/jdownie/repo/repo index ccf30da..8bbdea4 100755 --- a/jdownie/repo/repo +++ b/jdownie/repo/repo @@ -152,9 +152,9 @@ if __name__ == "__main__": if sys.argv[1] == "list": for k in cfg.keys(): print(k) - elif sys.argv[1] == "test": + elif sys.argv[1] == "status": dat = dict() - cache_file = filepath("test") + cache_file = filepath("status") if is_file_recent(cache_file): with open(cache_file, "rt") as fin: dat = json.load(fin) @@ -199,24 +199,6 @@ if __name__ == "__main__": flags = indicators(dat[k], "flags") print(f" {tl} {k.ljust(ml + 1)} {flags}") # print(json.dumps(dat, indent = 2)) - elif sys.argv[1] == "status": - dat = dict() - cache_file = filepath("status") - if is_file_recent(cache_file): - with open(cache_file, "rt") as fin: - dat = json.load(fin) - else: - for k in r: - path = os.path.expanduser( cfg[k]["path"] ) - if os.path.exists( path ): - cmd = "git -C \"{0}\" status --porcelain".format( path ) - output = execute_command(cmd).split("\n") - dat[k] = 0 if len(output[0]) == 0 else len(output) - with open(cache_file, "wt") as fout: - json.dump(dat, fout, indent = 2) - for k in dat: - status = "-" if dat[k] == 0 else dat[k] - print("{0} {1}".format(str(status).rjust(3), k)) elif sys.argv[1] in list( [ "sync", "lc", "lcs", "pull", "push", "fetch" ] ): thread_count = 10 with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor: