Created
December 13, 2023 23:57
-
-
Save Sarverott/ec39c1f797d5f194aaa3eed8d95c1313 to your computer and use it in GitHub Desktop.
good mood charm. this script is just as training for fun. it works, but it's not pretty, and it can suddenly autodestruct itself!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from os import path, system, remove | |
import sys | |
gitBashScript="""#!/usr/bin/env bash | |
case $1 in | |
"log") git -C "$2" log | cat ;; | |
"status") git -C "$2" status -s ;; | |
"add") git -C "$2" add * ;; | |
"commit") git -C "$2" commit -m "$(cat commit.txt)";; | |
"clone") git clone $2;; | |
*) echo "error"; | |
esac | |
""" | |
cloneRepo=sys.argv[1] | |
shFilePath=path.join(path.dirname(__file__), "the-lit-git.sh") | |
outputs=[] | |
with open(shFilePath, "w") as shFile: | |
shFile.write(gitBashScript) | |
def menu(): | |
global cloneRepo, shFilePath, outputs | |
for i in outputs: | |
print(i.stdout) | |
print("### GITOTRON ###") | |
print("clone pointer: ", cloneRepo) | |
print() | |
print("---options:") | |
options={} | |
cloneDirname=cloneRepo.split("/")[-1].split(".git")[0] | |
standardRun=["sh", shFilePath] | |
if path.exists(cloneDirname): | |
options["log"]=[cloneDirname] | |
options["status"]=[cloneDirname] | |
options["add"]=[cloneDirname] | |
options["commit"]=[cloneDirname] | |
options["clone"]=[cloneRepo] | |
options["exec"]=None | |
options["writefile"]=None | |
options["changeclone"]=None | |
options["exit"]=None | |
print("> "+"\n> ".join(options).upper()+"\n") | |
choice=input("choice: ") | |
if not choice in options: | |
return True | |
else: | |
if options[choice] is None: | |
if choice=="writefile": | |
with open("commit.txt","w") as fff: | |
fff.write(input("commit.txt content: ")) | |
elif choice=="changeclone": | |
cloneRepo=input("insert clone: ") | |
elif choice=="exec": | |
if path.exists(cloneDirname): | |
system(f'cd "{cloneDirname}"') | |
system("ls -al") | |
print() | |
system("pwd") | |
print() | |
system(input("exec-shell> ")) | |
print() | |
if path.exists(cloneDirname): | |
system('cd ..') | |
else: | |
return False | |
else: | |
outputs.append(subprocess.run(standardRun+[choice]+options[choice], capture_output=True)) | |
return True | |
while menu(): | |
system("clear") | |
remove(shFilePath) | |
subprocess.run(["rm", "-rf", cloneRepo.split("/")[-1].split(".git")[0]]) | |
remove(sys.argv[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment