From 5628942b4fe40a53eaf8756e8f1df65456f7376a Mon Sep 17 00:00:00 2001 From: Ruben Dahl Date: Sat, 19 Aug 2023 21:41:50 +0200 Subject: [PATCH] Initial commit --- README.md | 11 +++++++++++ gitignore | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 README.md create mode 100755 gitignore diff --git a/README.md b/README.md new file mode 100644 index 0000000..c495bfe --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# gitignore + +Quick and dirty way to generate a gitignore file. +Usage: +`gitignore ` + +You can either comma-separate this or space-separate this. You will be asked to save the file (to .gitignore in the current folder) or just view it. + +I recommend viewing it first and double checking if it's all good before running it again and saving. + +It includes gitignore values for Vim by default as this is the default editor I use. For CMake projects it also includes the folder `build/` as this is standard for my programming, and is not included by default from gitignore.io. diff --git a/gitignore b/gitignore new file mode 100755 index 0000000..f26a86b --- /dev/null +++ b/gitignore @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import requests +from sys import argv + +GITIGNORE_BASE_URL = "https://www.toptal.com/developers/gitignore/api/vim" + +def main() -> int: + FINAL_URL: str = GITIGNORE_BASE_URL + gitignore: str = "" + for arg in argv[1:]: + FINAL_URL += f",{arg.lower()}" + res: requests.Response = requests.get(FINAL_URL) + to_save: str = input("Gitignore file has been generated. Save? (Y/n) ") + gitignore: str = res.text + if "cmake" in argv: + gitignore += "\nbuild/" + if to_save.lower() == "y" or to_save == "" or to_save == "yes": + save_file(gitignore) + else: + print(gitignore) + return 0 + +def save_file(contents: str) -> None: + with open("./.gitignore", "w") as g: + g.write(contents) + print("Wrote contents to `.gitignore`.") + +if __name__ == "__main__": + raise SystemExit(main())