diff --git a/lib/helpers.bash b/lib/helpers.bash index 3a47cd4a..e7ef15ba 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -5,6 +5,16 @@ BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN=${BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN:-250 BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION=${BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION:-350} BASH_IT_LOAD_PRIORITY_SEPARATOR="---" +# Handle the different ways of running `sed` without generating a backup file based on OS +# - GNU sed (Linux) uses `-i` +# - BSD sed (macOS) uses `-i ''` +# To use this in Bash-it for inline replacements with `sed`, use the following syntax: +# sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file +BASH_IT_SED_I_PARAMETERS=(-i) +case "$(uname)" in + Darwin*) BASH_IT_SED_I_PARAMETERS=(-i "") +esac + function _command_exists () { _about 'checks for existence of a command' diff --git a/plugins/available/proxy.plugin.bash b/plugins/available/proxy.plugin.bash index 4f4bcbac..afd4dba4 100644 --- a/plugins/available/proxy.plugin.bash +++ b/plugins/available/proxy.plugin.bash @@ -370,7 +370,7 @@ ssh-disable-proxy () group 'proxy' if [ -f ~/.ssh/config ] ; then - sed -e's/^.*ProxyCommand/# ProxyCommand/' -i "" ~/.ssh/config + sed -e's/^.*ProxyCommand/# ProxyCommand/' "${BASH_IT_SED_I_PARAMETERS[@]}" ~/.ssh/config echo "Disabled SSH config proxy settings" fi } @@ -382,7 +382,7 @@ ssh-enable-proxy () group 'proxy' if [ -f ~/.ssh/config ] ; then - sed -e's/# ProxyCommand/ ProxyCommand/' -i "" ~/.ssh/config + sed -e's/# ProxyCommand/ ProxyCommand/' "${BASH_IT_SED_I_PARAMETERS[@]}" ~/.ssh/config echo "Enabled SSH config proxy settings" fi }