Skip to content

Instantly share code, notes, and snippets.

@rskelley9
Created October 1, 2017 05:14
Show Gist options
  • Save rskelley9/567252f545e7eb4bb97565e2c7795c43 to your computer and use it in GitHub Desktop.
Save rskelley9/567252f545e7eb4bb97565e2c7795c43 to your computer and use it in GitHub Desktop.
I created this script to remove the hidden .DS_Store file from my projects and automatically initialize and update my .gitignore file to keep it untracked.
#!/bin/sh
if [ -f "`find . -name .DS_Store`" ] ; then
if [ ! -f "`git rev-parse --is-inside-work-tree`" ] ; then
echo "no git repository found"
while true; do
read -p "Do you wish to initialize git repository in this folder $(echo $(pwd))?" yn
case $yn in
[Yy]* ) git init; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
if[ ! -f "`find . -name .gitignore`" ] ; then
touch $(pwd)/.gitignore && echo "created .gitignore"
fi
echo "removing .DS_Store"
find . -name .DS_Store -print0 | xargs -0 git rm
git config --global core.excludesfile "$(pwd)/.gitignore"
echo .DS_Store >> ~/.gitignore && echo ".DS_Store added to .gitignore"
else
echo ".DS_Store not found."
fi
@rskelley9
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment