mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00

When trying to run scripts/pretty with multiple ugly files staged, the for loop would treat two space-separated file names as a single file name. This prevented pretty from working on my machine. I fixed this issue by making cachedJS() (renamed to cachedFiles since it returns more than js files) return file names as a newline-separated list and using IFS=$'\n' to split the filenames on this character.
27 lines
775 B
Bash
Executable file
27 lines
775 B
Bash
Executable file
#!/bin/bash
|
|
|
|
source ./scripts/common
|
|
|
|
set -e
|
|
|
|
uglyFiles="$(ugly "$(cachedFiles)")"
|
|
|
|
if [ -n "$uglyFiles" ]; then
|
|
IFS=$'\n'
|
|
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
|