Last active
March 2, 2022 04:00
-
-
Save Ragnoroct/943bda9ed238c2919e751393ffcb2a72 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
# Diffs changelist to correct prettier format | |
# | |
# You can apply the prettier patch from this output | |
# xclip -out | git apply - | |
# pbpaste | git apply - | |
# cat /dev/clipboard | git apply - | |
git_root=$(git rev-parse --show-toplevel) | |
files_in_commit=$(git diff-index --name-only --diff-filter=ACMR HEAD -- ) | |
prettier="$git_root/node_modules/.bin/prettier" | |
prettier_success=0 | |
result=$(( result + $? )) | |
cd "$git_root" || exit | |
for file in $files_in_commit; do | |
# psuedo: prettier_format | git_diff | fix_filenames_for_patch_output | |
# shellcheck disable=SC2002 | |
cat "$file" | "$prettier" --stdin-filepath "$file"\ | |
| git --no-pager diff --color --no-index -- "$file" - \ | |
| sed "s/b\/-/b\/${file//\//\\/}/g" | |
if [ "${PIPESTATUS[2]}" -ne "0" ]; then | |
prettier_success=1 | |
fi | |
# gnu diff also works | |
# diff --color -u "$file" <(cat "$file" | "$prettier" --stdin-filepath "$file") | |
done | |
exit $prettier_success |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment