mirror of
https://github.com/DictXiong/dotfiles.git
synced 2025-12-19 20:47:49 +08:00
dogo: enhance, support -[0-9]*
This commit is contained in:
parent
8528199b2e
commit
4d8d41e8a0
16
scripts/dogo
16
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 <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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user