lib/helpers: the last remnants of the `$OSTYPE` have been swept away

- Figure out which `sed` we have by checking, not guessing.
pull/2061/head
John D Pell 2022-02-11 22:19:37 -08:00
parent ddf75f17ac
commit 95353f1a98
1 changed files with 10 additions and 7 deletions

View File

@ -8,16 +8,19 @@
: "${BASH_IT_LOAD_PRIORITY_COMPLETION:=350}" : "${BASH_IT_LOAD_PRIORITY_COMPLETION:=350}"
BASH_IT_LOAD_PRIORITY_SEPARATOR="---" BASH_IT_LOAD_PRIORITY_SEPARATOR="---"
# Handle the different ways of running `sed` without generating a backup file based on OS # Handle the different ways of running `sed` without generating a backup file based on provenance:
# - GNU sed (Linux) uses `-i` # - GNU sed (Linux) uses `-i''`
# - BSD sed (macOS) uses `-i ''` # - BSD sed (FreeBSD/macOS/Solaris/PlayStation) uses `-i ''`
# To use this in Bash-it for inline replacements with `sed`, use the following syntax: # To use this in Bash-it for inline replacements with `sed`, use the following syntax:
# sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file # sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file
BASH_IT_SED_I_PARAMETERS=('-i')
# shellcheck disable=SC2034 # expected for this case # shellcheck disable=SC2034 # expected for this case
case "$OSTYPE" in if sed --version > /dev/null 2>&1; then
'darwin'*) BASH_IT_SED_I_PARAMETERS=('-i' '') ;; # GNU sed accepts "long" options
esac BASH_IT_SED_I_PARAMETERS=('-i')
else
# BSD sed errors on invalid option `-`
BASH_IT_SED_I_PARAMETERS=('-i' '')
fi
function _command_exists() { function _command_exists() {
_about 'checks for existence of a command' _about 'checks for existence of a command'