Created
August 26, 2021 17:03
-
-
Save thisisnic/177308ac3da732d356f5413f89de6067 to your computer and use it in GitHub Desktop.
pre-commit file which runs styler on everything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
SOURCE_DIR='<path_to_project_root_goes_here>' | |
# Find all .R files which have been staged via git add | |
FILES_TO_STYLE=$(git diff --name-only --staged | grep "\.R") | |
for FILE in ${FILES_TO_STYLE[@]} | |
do | |
# Style all relevant files | |
R -e "styler::style_file('${SOURCE_DIR}${FILE}')" | |
# Stage the newly styled files | |
git add ${SOURCE_DIR}${FILE} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment