alias dkv="docker rm"
to be a much safer shell function:
dkv() {
if [[ "$1" == "rm" && -n "$2" ]]; then
read -r -p "Are you sure you want to delete volume '$2'? [Y/n] " confirm
confirm=${confirm:-Y}
if [[ "$confirm" =~ ^[Yy]$ ]]; then
# Disable history
set +o history
# Delete the volume
docker volume rm "$2"
# Re-enable history
set -o history
else
echo "Aborted."
fi
else
docker volume "$@"
fi
}
dkv rm ...
to make sure I never ever have this so easily accessible in my shell history (^R
):
$ awk '
/^#/ { ts = $0; next }
/^dkv rm/ { next }
{ if (ts) print ts; ts=""; print }
' ~/.bash_history > ~/.bash_history.tmp && mv ~/.bash_history.tmp ~/.bash_history && history -r
y
on a daily basis.Apart from that, aborting the removal should probably terminate the function with a non-zero exit code, something like
return 1
.
^R
and using fuzzy search which if you type fast you sometimes get wrong ๐