2023-07-20 14:25:13 -04:00
|
|
|
#!/usr/bin/env bash
|
2021-07-21 16:49:00 -04:00
|
|
|
|
2022-08-21 13:15:37 -04:00
|
|
|
# All common functions can be added to this file
|
2021-07-21 16:49:00 -04:00
|
|
|
|
2023-07-21 10:45:07 -04:00
|
|
|
exists() { type -t "$1" &> /dev/null; }
|
2022-08-16 07:51:45 -04:00
|
|
|
|
2021-07-21 16:49:00 -04:00
|
|
|
is_gnu_sed () {
|
2023-07-21 10:45:07 -04:00
|
|
|
sed --version &> /dev/null
|
2021-07-21 16:49:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
replace () {
|
2022-06-05 15:30:23 -04:00
|
|
|
echo "${1}"
|
2021-07-21 16:49:00 -04:00
|
|
|
if is_gnu_sed; then
|
2022-06-05 15:30:23 -04:00
|
|
|
sed -i -E "${1}" "${2}"
|
2021-07-21 16:49:00 -04:00
|
|
|
else
|
2022-06-05 15:30:23 -04:00
|
|
|
sed -i '' -E "${1}" "${2}"
|
2021-07-21 16:49:00 -04:00
|
|
|
fi
|
|
|
|
}
|
2022-08-16 07:51:45 -04:00
|
|
|
|
|
|
|
if ! exists gsed; then
|
|
|
|
if is_gnu_sed; then
|
|
|
|
function gsed() {
|
|
|
|
sed -i -E "$@"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
function gsed() {
|
|
|
|
sed -i '' -E "$@"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
fi
|