From 4d8d41e8a0a557f560f078e129504c9da366386c Mon Sep 17 00:00:00 2001 From: Dict Xiong Date: Sun, 13 Nov 2022 02:05:59 +0800 Subject: [PATCH] dogo: enhance, support -[0-9]* --- scripts/dogo | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/dogo b/scripts/dogo index f79d412..77a5e19 100755 --- a/scripts/dogo +++ b/scripts/dogo @@ -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 " + fmt_info "usage: $0 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