Compare commits

...

4 Commits

2 changed files with 44 additions and 34 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
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
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):
@ -131,9 +154,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)
@ -152,9 +175,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))
@ -168,31 +190,17 @@ 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)
ml = 0
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] == "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)
ml = len(k) if len(k) > ml else ml
for k in dat:
status = "-" if dat[k] == 0 else dat[k]
print("{0} {1}".format(str(status).rjust(3), k))
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] in list( [ "sync", "lc", "lcs", "pull", "push", "fetch" ] ):
thread_count = 10
with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor: