Skip to content

Instantly share code, notes, and snippets.

@abhishekkr
Last active February 20, 2024 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishekkr/dd4a4573b527952fa6728f9082b8e00f to your computer and use it in GitHub Desktop.
Save abhishekkr/dd4a4573b527952fa6728f9082b8e00f to your computer and use it in GitHub Desktop.
git-new: new Git Repo with custom content
#!/usr/bin/env bash
git-ignore(){
if [[ $# -eq 0 ]]; then
cat >> ./.gitignore << GITIGNORE
*swn
*swo
*swp
*~
*.tmp
*.json
*.config
*.cfg
*.lock
*.sock
*.venv
temp/*
GITIGNORE
else
for item in $@; do
echo "${item}" >> ./.gitignore
done
fi
}
git-readme(){
local _ABOUT_IT="$@"
local THIS_DIR=`pwd`
local README_FOR=`basename ${THIS_DIR} | sed -E 's/[-_]([a-z])/ \U\1/g' | sed -E 's/^([a-z])/\U\1/g' | sed -E 's/[^0-9a-zA-Z]/ /g'`
[[ -z "${README_FOR}" ]] && README_FOR="${THIS_DIR}"
cat >> ./README.md << READMEFOR
## ${README_FOR}
> it's autogenerated README, fill it to your content
${_ABOUT_IT}
---
READMEFOR
}
git-new(){
local REPO_TO_INIT="$1"
local THIS_DIR=`pwd`
local REPO_PATH="${THIS_DIR}/${REPO_TO_INIT}"
if [[ -d "${REPO_PATH}/.git" ]]; then
echo "${REPO_PATH} is already a git repo."
else
echo "initializing git repo: ${REPO_PATH}"
git init "${REPO_TO_INIT}"
fi
pushd "${REPO_TO_INIT}" >> /dev/null
if [[ -f "README.md" ]]; then
echo "${REPO_TO_INIT} already has a 'README.md'"
else
git-readme
fi
if [[ -f ".gitignore" ]]; then
echo "${REPO_TO_INIT} already has a '.gitignore'"
else
git-ignore
fi
popd
}
[[ $# -eq 0 ]] && echo "usage: $0 <git-repo-name>" && exit 123
git-new $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment