Skip to content

Commit

Permalink
adds docker functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lkwg82 committed Jan 27, 2024
1 parent 2fa3b31 commit 41decfa
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tools/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,33 @@ function docker_build_run(){
docker run --rm -ti $image $@
fi
}

function __docker_containers() {
gum spin --show-output --spinner dot --title 'list containers ...' -- \
"$SHELL" -c "docker ps --format '{{.Names}} {{.ID}}' | sort "

local cid=""
cid=$( \
printf "%-30s %s\n" \
$(gum spin --show-output --spinner dot --title 'list containers ...' -- \
"$SHELL" -c "docker ps --format '{{.Names}} {{.ID}}' | sort ") \
| gum choose \
| awk '{print $2}'
)
export CONTAINER_ID=$cid
}

function docker_inspect() {

( # keep env clean
__docker_containers
docker inspect $* "$CONTAINER_ID" | jq
)
}

function docker_logs() {
( # keep env clean
__docker_containers
docker logs --timestamps $* "$CONTAINER_ID"
)
}

0 comments on commit 41decfa

Please sign in to comment.