Skip to content

Instantly share code, notes, and snippets.

@SamuelDavis
Last active April 10, 2024 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamuelDavis/90084592848b74f5beb9a0c3dd114807 to your computer and use it in GitHub Desktop.
Save SamuelDavis/90084592848b74f5beb9a0c3dd114807 to your computer and use it in GitHub Desktop.
useful scripts
function pruneDocker () {
for CMD in $@
do
echo "Pruning ${CMD}s..."
IDS=$(docker $CMD ls --all --quiet 2> /dev/null || docker $CMD ls --quiet)
[ -z "$IDS" ] && echo "None found." && continue
echo "$IDS" | xargs -L1 docker $CMD rm --force
docker $CMD prune --force
done
}
function withOpts () {
while :; do
case "$1" in
"")
shift
break
;;
*)
if echo "$1 $2" | grep -qE "^--[_/a-z]+ [-_/a-zA-Z0-9]+$"; then
eval "${1#--}=$2"
shift 2
else
echo "Unexpected option pair: ${1:-?} ${2:-?}" && exit 1
fi
;;
esac
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment