dogo: enhance, support -[0-9]*

This commit is contained in:
Dict Xiong 2022-11-13 02:05:59 +08:00
parent 8528199b2e
commit 4d8d41e8a0

View File

@ -3,8 +3,20 @@
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: $0 <container>"
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)
else
$SUDO docker exec -it $1 sh -c 'if [ -x "$(command -v zsh)" ]; then zsh; elif [ -x "$(command -v bash)" ]; then echo "-->bash"; bash; else echo "-->sh"; sh; fi'
CONTAINER="$1"
fi
if [[ -z "$CONTAINER" ]]; then
fmt_error "container not found"
else
echo "--> $CONTAINER"
$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