Skip to content

Instantly share code, notes, and snippets.

@DerekV
Last active September 2, 2023 20:06
Show Gist options
  • Save DerekV/6665457 to your computer and use it in GitHub Desktop.
Save DerekV/6665457 to your computer and use it in GitHub Desktop.
Quickly build .gitignoreWorks with https://github.com/github/gitignore
#!/bin/bash
default_source=$HOME/.local/share
IFS=$'\n'
if [[ $# == 0 ]]
then
echo "Usage Example : "
echo " mkdir MyNewProject"
echo " cd MyNewProject"
echo " git init"
echo " gitignore.sh Java Maven Intellij Eclipse Emacs vim OSX Linux Windows >> .gitignore"
echo " git add .gitignore; git commit -m \"Import gitignores\""
exit 1
fi
if [[ -z "$GITIGNORES" ]]
then
echo 'GITIGNORES not defined, defaulting to ' $default_source/gitignore >&2
source="$default_source/gitignore"
else
source="$GITIGNORES"
fi
if [[ ! -e "$source" ]]
then
echo "$source not found... please set GITIGNORES to a directory containing gitignore files."
echo "These files should end in .gitignore, and can be in subfolders."
echo "Recommend you just do \"cd ${default_source}; git clone git@github.com:github/gitignore.git\""
exit 1
fi
for arg in "$@"
do
for file in $( find "$source" -iname "$arg".gitignore )
do
filedir=$(dirname "$file")
repo_url=$(cd "$filedir"; git config --get remote.origin.url)
echo
echo "### $arg $repo_url"
echo
cat "$file"
echo
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment