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