tridactyl/scripts/pretty
2018-05-21 16:34:39 +01:00

26 lines
752 B
Bash
Executable file

#!/bin/bash
source ./scripts/common
set -e
uglyFiles=$(ugly $(cachedJS))
if [ -n "$uglyFiles" ]; then
for file in "$uglyFiles"; do
if cmp -s <(staged $file) "$file"; then
prettier --write "$file"
git add "$file"
else
echo "WARN: Staged and working file differ: '$file'"
echo "WARN: Moving working file temporarily (this might upset your editor)"
# Get crazy: backup the working copy of the file, paste the staged version in its place, prettify, add, restore backup
backup=$(mktemp -p . $file.XXXXXXXXX)
mv "$file" "$backup"
staged "$file"|prettier --stdin-filepath "$file" > "$file"
git add "$file"
mv "$backup" "$file"
echo "WARN: Working file restored"
fi
done
fi