-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit-pretty
executable file
·39 lines (32 loc) · 955 Bytes
/
git-pretty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Runs prettier on vue/js/ts files in the most recent N commits.
set -ue
usage() {
(
echo "usage: ${0##*/} [-h|--help] [N]"
echo "Runs prettier on vue/js/ts files in the most recent N commits."
echo
echo "options:"
(
echo " -h, --help: show usage help"
echo " N: number of commits to consider, default is 1"
) | column -ts:
) >&2
exit 1
}
if echo "$*" | grep -Eq -- '--help\b|-h\b'; then
usage
fi
# shellcheck source=../.shell_control
# shellcheck disable=SC1091
source "$HOME/.shell_control" || echo "$(tput bold)error: ~/.shell_control not installed!$(tput sgr0)" >&2
BACK=${2:-1}
BACK=$((BACK - 1))
REFS="HEAD"
for i in $(seq 1 $BACK); do
REFS="$REFS HEAD~$i"
done
git show --pretty="" --name-only $REFS | grep -iE "\.vue$|\.js$|\.ts$" |
while read -r JSFILE; do
run "node_modules/.bin/prettier --write '$JSFILE'"
done