Skip to content

Instantly share code, notes, and snippets.

@cpeisert
Created May 15, 2023 17:57
Show Gist options
  • Save cpeisert/d5a01654c229664750be81b0f365951e to your computer and use it in GitHub Desktop.
Save cpeisert/d5a01654c229664750be81b0f365951e to your computer and use it in GitHub Desktop.
Format TypeScript files with Prettier from previous git commit
#!/bin/bash
#
# Get list of files from the most recent Git commit and run prettier to reformat using 2 spaces for tab width.
#
changed_files=$(git diff --name-only HEAD~1 HEAD)
for file in $changed_files
do
if [[ $file == *.ts ]]; then
# Change tab size to 2 spaces for TypeScript files
npx prettier --write --tab-width 2 $file
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment