mirror of
https://github.com/DictXiong/dotfiles.git
synced 2025-12-20 04:57:49 +08:00
dogo&doll: enhanced
This commit is contained in:
parent
4d8d41e8a0
commit
dae32c5293
14
scripts/dogo
14
scripts/dogo
@ -3,20 +3,28 @@
|
|||||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
source "$THIS_DIR/../tools/common.sh"
|
source "$THIS_DIR/../tools/common.sh"
|
||||||
|
|
||||||
|
DOCKER_FORMAT="{{.ID}} {{.Image}} {{.Names}}"
|
||||||
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
|
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
|
||||||
fmt_info "usage: $0 <container> or -[0-9]*"
|
fmt_info "usage: $0 <container> or -[0-9]*"
|
||||||
exit
|
exit
|
||||||
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
|
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
|
||||||
LAST="${1:1}"
|
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
|
else
|
||||||
|
CONTAINER_META="$1"
|
||||||
CONTAINER="$1"
|
CONTAINER="$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$CONTAINER" ]]; then
|
if [[ -z "$CONTAINER" ]]; then
|
||||||
fmt_error "container not found"
|
fmt_error "container not found"
|
||||||
else
|
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'
|
$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
|
fi
|
||||||
|
|||||||
19
scripts/doll
19
scripts/doll
@ -3,8 +3,23 @@
|
|||||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
source "$THIS_DIR/../tools/common.sh"
|
source "$THIS_DIR/../tools/common.sh"
|
||||||
|
|
||||||
|
DOCKER_FORMAT="{{.ID}} {{.Repository}}:{{.Tag}}"
|
||||||
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
|
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
|
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
|
fi
|
||||||
|
|||||||
@ -13,7 +13,7 @@ set_mirror()
|
|||||||
pacman_S()
|
pacman_S()
|
||||||
{
|
{
|
||||||
pacman -Syu
|
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()
|
router()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user