mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-10-23 05:08:16 +08:00
scripts: docker scripts (#26)
* dogo/doll dogo supports zsh/bash/sh; doll is introduced to launch a new docker container; update $SUDO in command.sh * update ci * fix regex * dogo: enhance, support -[0-9]* * dogo&doll: enhanced * zshrc: sibd and sob
This commit is contained in:
26
scripts/dogo
26
scripts/dogo
@@ -3,8 +3,28 @@
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/../tools/common.sh"
|
||||
|
||||
if [[ -z "$1" || "$1" =~ "-h|--help" ]]; then
|
||||
fmt_info "usage: dogo <container>"
|
||||
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
|
||||
$SUDO docker exec -it $1 zsh
|
||||
CONTAINER_META="$1"
|
||||
CONTAINER="$1"
|
||||
fi
|
||||
|
||||
if [[ -z "$CONTAINER" ]]; then
|
||||
fmt_error "container not found"
|
||||
else
|
||||
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
|
||||
|
||||
25
scripts/doll
Executable file
25
scripts/doll
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
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> 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
|
||||
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
|
||||
Reference in New Issue
Block a user