From 4c506316f0a94a3071f2f781a188d91b0eb743ff Mon Sep 17 00:00:00 2001 From: z3rOR0ne Date: Wed, 14 Dec 2022 21:04:08 -0800 Subject: [PATCH] :memo: Created gnore script for creating .gitignore files --- scripts/gnore | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 scripts/gnore diff --git a/scripts/gnore b/scripts/gnore new file mode 100755 index 00000000..41ad4ea9 --- /dev/null +++ b/scripts/gnore @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# set -vx + +# simple script that creates a .gitignore without an editor +# usage: gnore sample_file sample_dir +# usage: gnore (without arguments brings up prompt that recursively asks for +# items to add to .gitignore, q or quit quits the program) + +main() { + if [[ ! -f ".gitignore" ]]; then + touch .gitignore + fi + + if [[ "$#" -eq 0 ]] ; then + while : + do + read -e -r -p "add to .gitignore(q to quit): " addtogitignore + if [[ "$addtogitignore" == "q" || "$addtogitignore" == "quit" ]] ; then + break + exit 0 + else + echo "$addtogitignore" >> .gitignore + fi + done + else + ignores=("$@") + for ((i = 0; i < "${#ignores[@]}"; i++)) ; do + echo "${ignores[$i]}" >> .gitignore + done + exit 0 + fi +} + +main "$@"