Last active
October 17, 2020 11:26
-
-
Save michchan/99094512b6192e5b207e13ccdd50b4a0 to your computer and use it in GitHub Desktop.
Replace indentation tabs to spaces, 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
# Reference: | |
# https://stackoverflow.com/questions/11094383/how-can-i-convert-tabs-to-spaces-in-every-file-of-a-directory/11094422 | |
# http://azaleasays.com/2014/03/07/os-x-sed-does-not-recognize-tab-character/ | |
# "\( -iname \*.ts -o -iname \*.tsx -o -iname \*.js \)" means filtering only .ts .tsx, or .js files | |
# Tab to space | |
# * Press Ctrl+V and Tab to replace "\t" on Mac | |
find ./YOUR_PATH -type f \( -iname \*.ts -o -iname \*.tsx -o -iname \*.js \) -exec sed -i '' -E 's/\t/ /g' {} \; | |
# Convert 4 spaces to 2 spaces | |
find ./YOUR_PATH -type f \( -iname \*.ts -o -iname \*.tsx -o -iname \*.js \) -exec sed -i '' -E 's/ / /g' {} \; | |
# Remove trailing spaces | |
find ./YOUR_PATH -type f \( -iname \*.ts -o -iname \*.tsx -o -iname \*.js \) -exec sed -i '' 's/[[:space:]]\{1,\}$//' {} \+ | |
# Remove trailing newline | |
find ./YOUR_PATH -type f \( -iname \*.ts -o -iname \*.tsx -o -iname \*.js \) -exec sed -i '' -e :a -e '/^\n*$/{$d;N;};/\n$/ba' {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment