dogo&doll: enhanced

This commit is contained in:
Dict Xiong 2022-11-13 17:11:39 +08:00
parent 4d8d41e8a0
commit dae32c5293
3 changed files with 29 additions and 6 deletions

View File

@ -3,20 +3,28 @@
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/../tools/common.sh"
DOCKER_FORMAT="{{.ID}} {{.Image}} {{.Names}}"
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
fmt_info "usage: $0 <container> or -[0-9]*"
exit
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
LAST="${1:1}"
CONTAINER=$(docker container ls -qn ${LAST:-1} | tail -n 1)
if [[ "$LAST" == "0" ]]; then
# the latest running container
CONTAINER_META=($($SUDO docker container ls -l --filter "status=running" --format "$DOCKER_FORMAT"))
else
# the last nth container (all status)
CONTAINER_META=($($SUDO docker container ls -n ${LAST:-1} --format "$DOCKER_FORMAT" | tail -n 1))
fi
CONTAINER=${CONTAINER_META[0]}
else
CONTAINER_META="$1"
CONTAINER="$1"
fi
if [[ -z "$CONTAINER" ]]; then
fmt_error "container not found"
else
echo "--> $CONTAINER"
echo "--> ${CONTAINER_META[@]}"
$SUDO docker exec -it $CONTAINER sh -c 'if [ -x "$(command -v zsh)" ]; then echo "--> zsh"; zsh; elif [ -x "$(command -v bash)" ]; then echo "--> bash"; bash; else echo "--> sh"; sh; fi'
fi

View File

@ -3,8 +3,23 @@
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/../tools/common.sh"
DOCKER_FORMAT="{{.ID}} {{.Repository}}:{{.Tag}}"
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
fmt_info "usage: $0 <image>"
fmt_info "usage: $0 <image> or -[0-9]*"
exit
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
LAST="${1:1}"
# the last nth image
IMAGE_META=($($SUDO docker image ls --format "$DOCKER_FORMAT" | head -n ${LAST:-1} | tail -n 1))
IMAGE=${IMAGE_META[0]}
else
$SUDO docker run -itd $1 sh
IMAGE_META="$1"
IMAGE="$1"
fi
if [[ -z "$IMAGE" ]]; then
fmt_error "image not found"
else
echo "--> ${IMAGE_META[@]}"
echo $SUDO docker run -itd $IMAGE sh
fi

View File

@ -13,7 +13,7 @@ set_mirror()
pacman_S()
{
pacman -Syu
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip man-pages-posix
}
router()