2023-07-26 21:18:24 +08:00
|
|
|
#!/usr/bin/env bash
|
2022-08-26 20:43:00 +08:00
|
|
|
|
|
|
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
2022-11-05 19:45:21 +08:00
|
|
|
source "$THIS_DIR/../tools/common.sh"
|
2022-08-26 20:43:00 +08:00
|
|
|
|
2022-11-14 01:37:48 +08:00
|
|
|
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}"
|
|
|
|
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]}
|
2022-08-26 20:43:00 +08:00
|
|
|
else
|
2022-11-14 01:37:48 +08:00
|
|
|
CONTAINER_META="$1"
|
|
|
|
CONTAINER="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$CONTAINER" ]]; then
|
2022-11-15 01:28:38 +08:00
|
|
|
fmt_fatal "container not found"
|
2022-11-14 01:37:48 +08:00
|
|
|
else
|
2023-01-06 16:14:41 +08:00
|
|
|
fmt_note "--> ${CONTAINER_META[@]}"
|
2022-11-15 22:18:16 +08:00
|
|
|
$SUDO docker exec -it $CONTAINER sh -c 'export DFS="bash <(curl dfs.beardic.cn) -a"; if [ -x "$(command -v zsh)" ]; then echo "--> zsh"; unset DFS; zsh; elif [ -x "$(command -v bash)" ]; then echo "--> bash"; bash; else echo "--> sh"; sh; fi'
|
2022-08-26 20:43:00 +08:00
|
|
|
fi
|