Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions run-perlimports.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

# Run perlimports on perl scripts.
# Either with option --inplace-edit or --lint on some files.

set -eu

Expand All @@ -10,7 +11,29 @@ if ! command -v "${cmd}" >/dev/null 2>&1; then
exit 1
fi

if ! output=$("${cmd}" "$@" 2>&1); then
echo "${output}"
exit 1
fi
opts=
need_cp=
case $1 in
--inplace-edit) opts="$1"; need_cp=1; shift ;;
-*) opts="$1"; shift ;;
esac

for file in "$@"; do
if [ -n "${need_cp}" ]; then
cp -fp "${file}" "${file}.bak"
fi
if ! output=$("${cmd}" ${opts} "${file}" 2>&1); then
echo "${output}"
exit 1
fi
if [ -n "${need_cp}" ]; then
if cmp "$file" "${file}.bak" >/dev/null 2>&1; then
# nothing changed
mv "${file}.bak" "${file}"
else
# we have it in git
rm -f "${file}.bak"
fi
fi
done

17 changes: 15 additions & 2 deletions run-perltidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,26 @@ if ! command -v "${cmd}" >/dev/null 2>&1; then
fi

cfg=.perltidyrc
opts=(--nostandard-output --warning-output --backup-and-modify-in-place)
# --nostandard-output --warning-output --backup-and-modify-in-place --backup-method=move
opts=(-nst -w -b -bm=move)
if [[ ! -r "${cfg}" ]] && [[ ! -r "$HOME/${cfg}" ]]; then
opts=("--noprofile" "--perl-best-practices" "${opts[@]}")
# --noprofile" "--perl-best-practices
opts=("-npro" "-pbp" "${opts[@]}")
fi

if ! output=$("${cmd}" "${opts[@]}" "$@" 2>&1) ||
[[ "${output}" == *"## Please see file "*.ERR* ]]; then
echo "${output}"
exit 1
fi

for file in "$@"
do
if cmp "$file" "${file}.bak" >/dev/null 2>&1; then
# nothing changed
mv "${file}.bak" "${file}"
else
# we have it in git
rm -f "${file}.bak"
fi
done