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
repo_url="https://github.com/github/gitignore"
default_source=$HOME/gitignores
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 >&2
source="$default_source"
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."
exit 1
fi
for arg in "$@"
do
for file in $( find "$source" -iname "$arg"*.gitignore )
do
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