Guard on more exotic filenames.

pull/12/head
Joshua Potter 2023-12-03 14:28:55 -07:00
parent 07eb1fa382
commit 963283b74e
5 changed files with 81 additions and 38 deletions

View File

@ -1,12 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
FORMAT_FILES=$( STAGED=$(
git --no-pager diff --name-status --no-color --cached | \ git --no-pager diff --name-only --no-color --cached --diff-filter=d |
awk '$1 != "D" && $2 ~ /\.c$|\.h$/ {print $NF}' # Remove quotations used to surrounding filenames with special characters.
sed -e "s/^\"//" -e "s/\"$//g"
) )
if [ -n "$FORMAT_FILES" ]; then TARGETS=()
clang-format -i "$FORMAT_FILES" while IFS= read -r FILENAME
git add "$FORMAT_FILES" do
if [[ "$FILENAME" =~ .*\.c ]] || [[ "$FILENAME" == .*\.h ]]; then
TARGETS+=("${FILENAME}")
fi
done <<< "$STAGED"
if (( ${#TARGETS[@]} )); then
clang-format -i "${TARGETS[@]}"
git add "${TARGETS[@]}"
fi fi

View File

@ -1,12 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
FORMAT_FILES=$( STAGED=$(
git --no-pager diff --name-status --no-color --cached | \ git --no-pager diff --name-only --no-color --cached --diff-filter=d |
awk '$1 != "D" && $2 ~ /\.exs?$/ {print $NF}' # Remove quotations used to surrounding filenames with special characters.
sed -e "s/^\"//" -e "s/\"$//g"
) )
if [ -n "$FORMAT_FILES" ]; then TARGETS=()
mix format "$FORMAT_FILES" while IFS= read -r FILENAME
git add "$FORMAT_FILES" do
if [[ "$FILENAME" =~ .*\.exs? ]]; then
TARGETS+=("${FILENAME}")
fi
done <<< "$STAGED"
if (( ${#TARGETS[@]} )); then
mix format "${TARGETS[@]}"
git add "${TARGETS[@]}"
fi fi

View File

@ -1,12 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
FORMAT_FILES=$( STAGED=$(
git --no-pager diff --name-status --no-color --cached | \ git --no-pager diff --name-only --no-color --cached --diff-filter=d |
awk '$1 != "D" && $2 ~ /\.jsx?$|\.tsx?$/ {print $NF}' # Remove quotations used to surrounding filenames with special characters.
sed -e "s/^\"//" -e "s/\"$//g"
) )
if [ -n "$FORMAT_FILES" ]; then TARGETS=()
prettier --write "$FORMAT_FILES" while IFS= read -r FILENAME
git add "$FORMAT_FILES" do
if [[ "$FILENAME" =~ .*\.jsx? ]] || [[ "$FILENAME" == .*\.tsx? ]]; then
TARGETS+=("${FILENAME}")
fi
done <<< "$STAGED"
if (( ${#TARGETS[@]} )); then
prettier --write "${TARGETS[@]}"
git add "${TARGETS[@]}"
fi fi

View File

@ -1,22 +1,29 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
MIX_FILES=$( STAGED=$(
git --no-pager diff --name-status --no-color --cached | \ git --no-pager diff --name-only --no-color --cached --diff-filter=d |
awk '$1 != "D" && $2 ~ /\.exs?$/ {print $NF}' # Remove quotations used to surrounding filenames with special characters.
sed -e "s/^\"//" -e "s/\"$//g"
) )
if [ -n "$MIX_FILES" ]; then MIX_TARGETS=()
mix format "$MIX_FILES" WEB_TARGETS=()
git add "$MIX_FILES" while IFS= read -r FILENAME
do
if [[ "$FILENAME" =~ .*exs? ]]; then
MIX_TARGETS+=("${FILENAME}")
elif [[ "$FILENAME" =~ .*jsx? ]] || [[ "$FILENAME" =~ .*tsx? ]]; then
WEB_TARGETS+=("${FILENAME}")
fi
done <<< "$STAGED"
if (( ${#MIX_TARGETS[@]} )); then
mix format "${MIX_TARGETS[@]}"
git add "${MIX_TARGETS[@]}"
fi fi
WEB_FILES=$( if (( ${#WEB_TARGETS[@]} )); then
git --no-pager diff --name-status --no-color --cached | \ prettier --write "${WEB_TARGETS[@]}"
awk '$1 != "D" && $2 ~ /\.jsx?$|\.tsx?$/ {print $NF}' git add "${WEB_TARGETS[@]}"
)
if [ -n "$WEB_FILES" ]; then
prettier --write "$WEB_FILES"
git add "$WEB_FILES"
fi fi

View File

@ -1,12 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
FORMAT_FILES=$( STAGED=$(
git --no-pager diff --name-status --no-color --cached | \ git --no-pager diff --name-only --no-color --cached --diff-filter=d |
awk '$1 != "D" && $2 ~ /\.py$/ {print $NF}' # Remove quotations used to surrounding filenames with special characters.
sed -e "s/^\"//" -e "s/\"$//g"
) )
if [ -n "$FORMAT_FILES" ]; then TARGETS=()
black --quiet "$FORMAT_FILES" while IFS= read -r FILENAME
git add "$FORMAT_FILES" do
if [[ "$FILENAME" =~ .*\.py ]]; then
TARGETS+=("${FILENAME}")
fi
done <<< "$STAGED"
if (( ${#TARGETS[@]} )); then
black --quiet "${TARGETS[@]}"
git add "${TARGETS[@]}"
fi fi