Skip to content

Instantly share code, notes, and snippets.

@IObert
Last active March 3, 2021 11:02
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save IObert/1f2236c648c4aecdbd3e463d85c197ca to your computer and use it in GitHub Desktop.
Save IObert/1f2236c648c4aecdbd3e463d85c197ca to your computer and use it in GitHub Desktop.
Simple aliases to make the life of CF developers easier
function checkCfStatus () {
if echo $(cf a 2>&1 >/dev/null) | grep -q 'The token expired\|Not logged in' $OUTPUT; then
cf login
fi
}
function preexecHook () {
if echo $1 | grep -q "cf "; then
checkCfStatus
fi
}
add-zsh-hook preexec preexecHook
wipeCFApps () {
checkCfStatus
for APP in `cf apps | tail -n +4 | awk '{ print $1}' `; do cf delete -f -r $APP; done
# cf delete-orphaned-routes
}
wipeCFServices () {
checkCfStatus
for SERIVCE in `cf s | tail -n +4 | awk '{ print $1}' `; do cf ds -f $SERIVCE; done
}
wipeCFServiceKeys () {
checkCfStatus
for SERIVCE in `cf s | tail -n +4 | awk '{ print $1}' `
do
for SERIVCEKEY in `cf sk $SERIVCE | tail -n +4`
do
cf dsk -f $SERIVCE $SERIVCEKEY
done
done
}
wipeCFMtas() {
checkCfStatus
for MTA in `cf mtas | tail -n +4 | awk '{ print $1}'`; do cf undeploy $MTA --delete-services --delete-service-keys -f;done
}
removeCF () {
echo Going to remove all apps and services that contain \'$1\':
for APP in `cf apps | tail -n +5 | grep $1 | awk '{ print $1}' `; do cf delete -f -r $APP; done
for SERIVCE in `cf s | tail -n +4 | grep $1 | awk '{ print $1}'`; do cf ds -f $SERIVCE; done
}
CFLink () {
checkCfStatus
echo "https://"$(cf a | grep $1 | awk '{print $6}')
}
wipeCF () {
wipeCFServiceKeys
wipeCFApps
wipeCFServices
}
@IObert
Copy link
Author

IObert commented May 13, 2019

Run curl https://gist.githubusercontent.com/IObert/1f2236c648c4aecdbd3e463d85c197ca/raw/bd8a2373aa73f85b27f810649d7a02e84243ceca/.zhsrc >> .zhsrc to add these aliases

@maxstreifeneder
Copy link

I have an additional line as part of the removeCF() function to get rid of MTAs and the corresponding artefacts
bash:
for MTA in `cf mtas | tail -n +4 | awk '{ print $1}'`; do cf undeploy $MTA --delete-services --delete-service-keys -f;done

@IObert
Copy link
Author

IObert commented Mar 1, 2021

Thanks, I added this line to the file (as a new function) :)

@maxstreifeneder
Copy link

excellent! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment