PK!xgit/__init__.pyPK!_q[xgit/__main__.pyimport sys import subprocess import shlex from pathlib import Path import requests from .utils import trim_indent, call_multiline CMD = { "init" : "Initialize new git along with .gitignore", "gi" : "Generate gitignore from files in the directory", "commit": "Commit to git with the following message", "cpush" : "Commit current changes and push to remote", "push" : "Push changes to remote", "pull" : "Pull changes from remote" } def main(): argv = sys.argv if len(argv) <= 1: cli_default() elif argv[1] == "init": cli_init() elif argv[1] in {"commit", "cpush"}: try: cli_commit(argv[2]) except IndexError: cli_commit(input("Please input your commit message: ")) if argv[1] == "cpush": cli_push() elif argv[1] == "gi": cli_gi() elif argv[1] == "push": cli_push() elif argv[1] in {"-h", "--help", "help"}: print(trim_indent(""" Acceptable commands: xgit init {init} xgit commit message {commit} xgit cpush message {cpush} xgit gi {gi} xgit push {push} xgit pull {pull} xgit Prompt for choices """.format(**CMD))) def cli_default(): choice = input(trim_indent(""" What do you want to do? 1. {init} 2. {commit} 3. {cpush} 4. {gi} 5. {push} 6. {pull} Please select [1-6]: """.format(**CMD))) if choice == "1": cli_init() elif choice in {"2", "3"}: cli_commit(input("Please input your commit message: ")) if choice == "3": cli_push() elif choice == "4": cli_gi() elif choice == "5": cli_push() elif choice == "6": cli_pull() def cli_init(): cli_gi(_commit=False) subprocess.call(["git", "init"]) def cli_commit(s: str): call_multiline(""" git add . git commit -m {} """.format(shlex.quote(s))) def cli_gi(_commit=True): try: gitignore_rows = Path(".gitignore").read_text().split("\n") except FileNotFoundError: gitignore_rows = [] _append_gitignore( src=Path(__file__).parent.joinpath("gitignore/{}.gitignore".format("global")).read_text().split("\n"), dst=gitignore_rows) matched = set() for spec, filetypes in { "py": ["py"], "jvm": ["java", "kt"], "dart": ["dart"], "node": ["js", "ts", "jsx", "tsx"] }.items(): for filetype in filetypes: try: next(Path(".").glob("**/*.{}".format(filetype))) if spec not in matched: try: _append_gitignore( src=Path(__file__).parent.joinpath("gitignore/{}.gitignore".format(spec)).read_text().split("\n"), dst=gitignore_rows) except FileNotFoundError: pass matched.add(spec) matched.add(filetype) except StopIteration: pass if len(matched) > 0: r = requests.get("https://www.gitignore.io/api/{}".format(",".join({ "kt": "kotlin", "py": "python" }.get(k, k) for k in matched))) _append_gitignore( src=r.text.split("\n"), dst=gitignore_rows) with open(".gitignore", "w") as f: f.write("\n".join(gitignore_rows) + "\n") if _commit: subprocess.call(["sh", "-c", "git ls-files -i --exclude-from=.gitignore | xargs git rm --cached"]) cli_commit(input("Please input your commit message.")) def cli_push(): if not subprocess.check_output(["git", "config", "remote.origin.url"]): subprocess.call(["git", "remote", "add", "origin", shlex.quote(input("Please input the Git origin: "))]) subprocess.call(["git", "push", "origin", "master"]) def cli_pull(): subprocess.call(["git", "pull", "origin", "master"]) def _append_gitignore(src: list, dst: list): for row in src: if row not in dst: if not row.startswith("#"): dst.append(row) PK!͐xgit/gitignore/dart.gitignore.pub/ PK!: xgit/gitignore/global.gitignore.vscode/ PK!exgit/gitignore/jvm.gitignore.idea/ PK!exgit/gitignore/py.gitignore.idea/ PK!_ xgit/utils.pyimport re import subprocess def trim_indent(s: str) -> str: def process_match(match_obj): if match_obj is None: return 0 else: return len(match_obj.group()) rows = s.lstrip("\n").rstrip().split("\n") ws = min(process_match(re.match(r" +", r)) for r in rows) return "\n".join(r[ws:] for r in rows) def call_multiline(s: str): for row in trim_indent(s).split("\n"): if row.strip(): subprocess.call(["sh", "-c", row.strip()]) PK!Hk(+%xgit-0.1.5.dist-info/entry_points.txtN+I/N.,()H,z񹉙yV PK!ޡ::xgit-0.1.5.dist-info/LICENSEMIT License Copyright (c) 2019 Pacharapol Withayasakpunt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HnHTUxgit-0.1.5.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HQВz9fxgit-0.1.5.dist-info/METADATATmo0_q0&]WR4Ӑ`bj/!Mc! 6ICs=/'Nh~:cxܖ³|/첩kn h#rMrU k-Bo:X;Z+x+<;]cbxI+˦SP5O hN#3rd{~zcj[ ,x^>;~cHBf0~]I.{#,dё-rL{DrĚj`Y/O!YDQsYX]Z^BpUP揵<=^g`;=z&t)X0Yh^n/m}.xD+'W>{SB~b%p 0| BUcBw)j#PK!H]Bݨxgit-0.1.5.dist-info/RECORDKcP},f!B M<匿25ӝ,l9{V]p7lTF8uE':hGhȭR ̪[J Di/MO)=E֏% ]~ S?!$NTE׏{`>U6Ù2e X*"4dpNƳ&h8j~?OE]r=+%cmf a)^HlZ܊y1+Vm T5F^ @pU35Hי:5>(0v{)tnC]MC( A~Gjh{ցq ..QtDc+7& v2p?PAMppOXpy0k7IGcw*5+ӁAMȞaת%uBPK!xgit/__init__.pyPK!_q[.xgit/__main__.pyPK!͐xgit/gitignore/dart.gitignorePK!: )xgit/gitignore/global.gitignorePK!eoxgit/gitignore/jvm.gitignorePK!exgit/gitignore/py.gitignorePK!_ xgit/utils.pyPK!Hk(+%xgit-0.1.5.dist-info/entry_points.txtPK!ޡ::xgit-0.1.5.dist-info/LICENSEPK!HnHTUxgit-0.1.5.dist-info/WHEELPK!HQВz9fxgit-0.1.5.dist-info/METADATAPK!H]Bݨxgit-0.1.5.dist-info/RECORDPK [>