Skip to content

Commit

Permalink
Merge pull request #112 from kelbyers/docker
Browse files Browse the repository at this point in the history
d-image-rm: handle multiple tags for same image
  • Loading branch information
unixorn authored Jan 14, 2025
2 parents 06e2946 + 3932254 commit c9c4f72
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bin/d-image-rm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function debug() {
}

function fail() {
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
}

function has() {
Expand All @@ -27,11 +27,15 @@ function has() {

# Select a docker image or images to remove
function drmi() {
docker images | sed 1d | fzf -q "$1" --no-sort -m --tac | awk '{ print $3 }' | xargs -r docker rmi
# if the image has no tag, use the image id, otherwise use the image name and
# tag; allows removing a tag from an image with multiple tags
docker images | sed 1d | fzf -q "$1" --no-sort -m --tac |
awk '{ print ($2=="<none>")?$3:$1 ":" $2 }' |
xargs -r docker rmi
}

if has docker; then
drmi "$@"
else
"Cannot find docker in $PATH"
fi
fi

0 comments on commit c9c4f72

Please sign in to comment.