Lazy commit on frankie.

This commit is contained in:
James Downie 2025-06-30 20:16:32 +10:00
commit 96dc04c8fb
2 changed files with 43 additions and 34 deletions

View File

@ -231,3 +231,4 @@ You should also get your employer (if you work as a programmer) or school, if an
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 <https://www.gnu.org/philosophy/why-not-lgpl.html>. 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 <https://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -9,14 +9,37 @@ import json
import time import time
from pathlib import Path from pathlib import Path
def ind(): def to_keycap(ch: str) -> str:
print('\u2B06\uFE0F\u0031\uFE0F\u20E3') # ⬆1 """
print('\u2B07\uFE0F\u0032\uFE0F\u20E3') # ⬇2 Converts a single character (0-9, #, *) into a keycap emoji.
for i in range(1, 6): Returns the original character if not valid for keycaps.
digit = str(i) """
keycap = digit + '\uFE0F\u20E3' if ch in '0123456789#*':
print(f"\u2B06\uFE0F{keycap} Up {i}") return ch + '\uFE0F\u20E3'
print(f"\u2B07\uFE0F{keycap} Down {i}") 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): def rm(p):
if os.path.exists(p): if os.path.exists(p):
@ -131,9 +154,9 @@ if __name__ == "__main__":
if sys.argv[1] == "list": if sys.argv[1] == "list":
for k in cfg.keys(): for k in cfg.keys():
print(k) print(k)
elif sys.argv[1] == "test": elif sys.argv[1] == "status":
dat = dict() dat = dict()
cache_file = filepath("test") cache_file = filepath("status")
if is_file_recent(cache_file): if is_file_recent(cache_file):
with open(cache_file, "rt") as fin: with open(cache_file, "rt") as fin:
dat = json.load(fin) dat = json.load(fin)
@ -152,9 +175,8 @@ if __name__ == "__main__":
prop = m.group(1) prop = m.group(1)
rest = m.group(2) rest = m.group(2)
if prop == "ab": if prop == "ab":
print("ding") m2 = re.match(r"[+](\d+)\s[-](\d+)", rest)
m2 = re.match(r"[+](\d+)\n[-](\d+)", rest) p2 = rest
p2 = "?"
if m2: if m2:
p2 = dict() p2 = dict()
p2["push"] = int(m2.group(1)) p2["push"] = int(m2.group(1))
@ -168,31 +190,17 @@ if __name__ == "__main__":
else: else:
n = n + 1 n = n + 1
props["n"] = n props["n"] = n
print(props) dat[k] = props
dat[k] = n
with open(cache_file, "wt") as fout: with open(cache_file, "wt") as fout:
json.dump(dat, fout, indent = 2) json.dump(dat, fout, indent = 2)
ml = 0
for k in dat: for k in dat:
status = "-" if dat[k] == 0 else dat[k] ml = len(k) if len(k) > ml else ml
print("{0} {1}".format(str(status).rjust(3), k))
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: for k in dat:
status = "-" if dat[k] == 0 else dat[k] tl = indicators(dat[k], "tl")
print("{0} {1}".format(str(status).rjust(3), k)) flags = indicators(dat[k], "flags")
print(f" {tl} {k.ljust(ml + 1)} {flags}")
# print(json.dumps(dat, indent = 2))
elif sys.argv[1] in list( [ "sync", "lc", "lcs", "pull", "push", "fetch" ] ): elif sys.argv[1] in list( [ "sync", "lc", "lcs", "pull", "push", "fetch" ] ):
thread_count = 10 thread_count = 10
with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor: with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor: