Skip to content

Instantly share code, notes, and snippets.

@thisisnic
Created August 26, 2021 17:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisisnic/177308ac3da732d356f5413f89de6067 to your computer and use it in GitHub Desktop.
Save thisisnic/177308ac3da732d356f5413f89de6067 to your computer and use it in GitHub Desktop.
pre-commit file which runs styler on everything
#!/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