Created
May 10, 2018 13:58
-
-
Save taktran/32ae9d551d99416b0f26fdf93fef001d to your computer and use it in GitHub Desktop.
Update indent of files from 4 to 2 spaces
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 | |
# | |
# Usage: | |
# | |
# Find all files | |
# | |
# ls -1 $PWD/*.js > files.txt | |
# | |
# Run script | |
# | |
# ./update-indent.sh files.txt > files-output.log | |
# | |
# Based on https://superuser.com/a/860725/28191 | |
while read filename; do | |
if ! [[ -r "$filename" ]]; then | |
echo "Skipping '$filename' because not readable" | |
continue | |
fi | |
tempfile="$(mktemp)" | |
if perl -ne '$_ =~ s|^(( )+)|" " x (length($1)/4)|eg; print $_' < "$filename" > "$tempfile"; then | |
# Uncomment if you want the original file | |
#mv "$filename" "$filename".orig | |
mv "$tempfile" "$filename" | |
echo "Success processing '$filename'" | |
else | |
echo "Failure processing '$filename'" | |
fi | |
done < "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment