From dafe41aec2fb46244e084c0455c08f80ad4cf2ba Mon Sep 17 00:00:00 2001 From: Tarun Sepuri Date: Thu, 21 May 2020 00:27:52 -0400 Subject: [PATCH] Does not require additional permission and works from any directory --- .my_commands.sh | 15 +++------------ create.py | 9 ++++++--- requirements.txt | 1 + 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.my_commands.sh b/.my_commands.sh index 3844488..4a9ceb6 100644 --- a/.my_commands.sh +++ b/.my_commands.sh @@ -1,15 +1,6 @@ #!/bin/bash - +SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" function create() { - cd - source .env - python create.py $1 - cd $FILEPATH$1 - git init - git remote add origin git@github.com:$USERNAME/$1.git - touch README.md - git add . - git commit -m "Initial commit" - git push -u origin master - code . + cd $SCRIPTPATH + python3 create.py $1 } diff --git a/create.py b/create.py index 7a33ca5..c642962 100644 --- a/create.py +++ b/create.py @@ -2,7 +2,7 @@ import os from github import Github from dotenv import load_dotenv - +import pygit2 load_dotenv() path = os.getenv("FILEPATH") @@ -11,10 +11,13 @@ def create(): folderName = str(sys.argv[1]) - os.makedirs(path + str(folderName)) user = Github(username, password).get_user() repo = user.create_repo(folderName) - print("Succesfully created repository {}".format(folderName)) + repo.create_file("README.md", "Initial commit","") + repoClone = pygit2.clone_repository(repo.git_url, path + str(folderName)) + print(f"Succesfully created repository {folderName}") + os.chdir(path+str(folderName)) + os.system("code .") if __name__ == "__main__": create() diff --git a/requirements.txt b/requirements.txt index 0460963..7b06bc8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ selenium PyGithub python-dotenv +pygit2 \ No newline at end of file