Skip to content

Instantly share code, notes, and snippets.

@Bad-ptr
Last active December 19, 2015 23:59
Show Gist options
  • Save Bad-ptr/6038839 to your computer and use it in GitHub Desktop.
Save Bad-ptr/6038839 to your computer and use it in GitHub Desktop.
Construct .gitignore file
#!/bin/bash
INCLUDE="Emacs vim Archives CVS SVN Mercurial Tags OSX Windows Linux C Go"
EXCLUDE="Bancha Objective-C"
if [ -d "./gitignore" ]; then
cd "./gitignore"
echo "-> git pull"
git pull
if [ $? -eq 0 ]; then
echo "[OK] Successfully pulled."
else
echo "[WARNING] Cannot pull."
fi
cd ../
else
echo "-> git clone https://github.com/github/gitignore.git"
git clone https://github.com/github/gitignore.git
if [ $? -eq 0 ]; then
echo "[OK] Successfully cloned."
else
echo "[FAIL] Cannot clone. Aborting."
exit 1
fi
fi
GLOBAL_FILES=`find ./gitignore/Global -maxdepth 1 -type f -iname '*.gitignore' -not -path "*.git/*"`
PROG_LANG_FILES=`find ./gitignore -maxdepth 1 -type f -iname '*.gitignore' -not -path "*.git/*"`
if [ -f ".gitignore_global" ]; then
rm .gitignore_global
fi
if [ -f ".gitignore_everything" ]; then
rm .gitignore_everything
fi
if [ -f ".gitignore_inclusive" ]; then
rm .gitignore_inclusive
fi
if [ -f ".gitignore_exclusive" ]; then
rm .gitignore_exclusive
fi
while read -r file_name; do
base_name=`basename ${file_name}`
#extension="${base_name##*.}"
fname="${base_name%.*}"
echo "" >> .gitignore_global
echo "" >> .gitignore_everything
echo "##### ${fname} #####" >> .gitignore_global
echo "##### ${fname} #####" >> .gitignore_everything
file_content=`cat ${file_name}`
echo "${file_content}" >> .gitignore_global
echo "${file_content}" >> .gitignore_everything
echo "" >> .gitignore_global
echo "" >> .gitignore_everything
if [[ ${INCLUDE} =~ (^| )${fname}($| ) ]]; then
echo "" >> .gitignore_inclusive
echo "##### ${fname} #####" >> .gitignore_inclusive
echo "${file_content}" >> .gitignore_inclusive
echo "" >> .gitignore_inclusive
fi
if [[ ! ${EXCLUDE} =~ (^| )${fname}($| ) ]]; then
echo "" >> .gitignore_exclusive
echo "##### ${fname} #####" >> .gitignore_exclusive
echo "${file_content}" >> .gitignore_exclusive
echo "" >> .gitignore_exclusive
fi
done <<< "${GLOBAL_FILES}"
while read -r file_name; do
base_name=`basename ${file_name}`
fname="${base_name%.*}"
echo "" >> .gitignore_everything
echo "##### ${fname} #####" >> .gitignore_everything
file_content=`cat ${file_name}`
echo "${file_content}" >> .gitignore_everything
echo "" >> .gitignore_everything
if [[ ${INCLUDE} =~ (^| )${fname}($| ) ]]; then
echo "" >> .gitignore_inclusive
echo "##### ${fname} #####" >> .gitignore_inclusive
echo "${file_content}" >> .gitignore_inclusive
echo "" >> .gitignore_inclusive
fi
if [[ ! ${EXCLUDE} =~ (^| )${fname}($| ) ]]; then
echo "" >> .gitignore_exclusive
echo "##### ${fname} #####" >> .gitignore_exclusive
echo "${file_content}" >> .gitignore_exclusive
echo "" >> .gitignore_exclusive
fi
done <<< "${PROG_LANG_FILES}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment