mirror of
https://github.com/DictXiong/dotfiles.git
synced 2024-11-24 16:57:00 +08:00
Dict Xiong
c354f980bb
* piv logi fix * dogo: $DFS * snasp; doll: $2 for the name * DFS_UPDATE_CHANNEL? * git-branches * ci: git-branches Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
31 lines
1.1 KiB
Bash
Executable File
31 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
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}"
|
|
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_fatal "container not found"
|
|
else
|
|
echo "--> ${CONTAINER_META[@]}"
|
|
$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'
|
|
fi
|