Skip to content

Instantly share code, notes, and snippets.

@troy0820
Last active April 18, 2020 03:59
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 troy0820/c1dbd27f30e0c38f015b15113eb7a2b9 to your computer and use it in GitHub Desktop.
Save troy0820/c1dbd27f30e0c38f015b15113eb7a2b9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
files=$(find . -name ".editorconfig" ! -path './vendor/*')
gitfiles=$(git diff --cached --name-only)
if [[ "${files}" == "./.editorconfig" ]]; then
echo -e "\033[032m.editorconfig file exists \033[0m"
for f in $gitfiles
do
git add $f
done
else
echo -e "\033[032mNo editorconfig; Adding one now \033[0m"
touch .editorconfig
cat <<EOF > .editorconfig
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# Change these settings to your own preference
indent_style = space
indent_size = 2
# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{Makefile,**.mk}]
# Use tabs for indentation (Makefiles require tabs)
indent_style = tab
EOF
echo -e "\033[032Now you have one\033[0m"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment