1 # Helper function for calling sed on files and checking if the
2 # file is actually changed
4 # NOTE: this will not check if the input is valid, you can problably
5 # make it execute arbirtrary commands via passing '; cmd' to a vsed
9 local files
=() regexes
=() OPTIND OPTSTRING
="ie:" has_inline
=
11 eval set -- "$(getopt -s bash "$OPTSTRING" "$@
")";
13 while getopts "$OPTSTRING" opt
; do
16 e
) regexes
+=("$OPTARG") ;;
21 if ! [ "$has_inline" ]; then
22 msg_red
"$pkgver: vsed: you must specify -i.\n"
26 shift $
(($OPTIND - 1))
28 if [ ${#regexes[@]} -eq 0 ] && [ $# -ge 2 ]; then
33 if [ ${#regexes[@]} -eq 0 ]; then
34 msg_red
"$pkgver: vsed: no regexes specified.\n"
42 if [ ${#files[@]} -eq 0 ]; then
43 msg_red
"$pkgver: vsed: no files specified.\n"
47 for f
in "${files[@]}"; do
48 olddigest
="$($XBPS_DIGEST_CMD "$f")"
49 olddigest
="${olddigest%% *}"
51 for rx
in "${regexes[@]}"; do
52 sed -i "$f" -e "$rx" ||
{
53 msg_red
"$pkgver: vsed: sed call failed with regex \"$rx\" on file \"$f\"\n"
57 newdigest
="$($XBPS_DIGEST_CMD "$f")"
58 newdigest
="${newdigest%% *}"
61 if [ -n "$XBPS_STRICT" ]; then
65 if [ "$olddigest" = "$newdigest" ]; then
66 $msgfunc "$pkgver: vsed: regex \"$rx\" didn't change file \"$f\"\n"
68 olddigest
="${newdigest}"