Merge pull request #1413 from nwinkler/proxy-sed-fix

Make sed replacements work for both BSD and GNU sed
pull/1417/head
Nils Winkler 2019-07-31 08:52:09 +02:00 committed by GitHub
commit 3116754a52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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_DEFAULT_COMPLETION=${BASH_IT_LOAD_PRIORITY_DEFAULT_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
# - 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 () function _command_exists ()
{ {
_about 'checks for existence of a command' _about 'checks for existence of a command'

View File

@ -370,7 +370,7 @@ ssh-disable-proxy ()
group 'proxy' group 'proxy'
if [ -f ~/.ssh/config ] ; then 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" echo "Disabled SSH config proxy settings"
fi fi
} }
@ -382,7 +382,7 @@ ssh-enable-proxy ()
group 'proxy' group 'proxy'
if [ -f ~/.ssh/config ] ; then 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" echo "Enabled SSH config proxy settings"
fi fi
} }