[zsh] Add sdocker function

This commit is contained in:
Mathieu Maret 2015-06-11 11:18:17 +02:00 committed by Mathieu Maret
parent 1a9cd4d46d
commit 02bd808f80

View File

@ -159,3 +159,31 @@ function secure_chromium {
exit exit
} }
sdocker (){
if [ -n "$SSH_AUTH_SOCK" ]; then
SSH_AUTH_ARGS="-v $SSH_AUTH_SOCK:/tmp/ssh_auth -e SSH_AUTH_SOCK=/tmp/ssh_auth"
fi
AOSP_ARGS=${AOSP_ARGS:--it}
img=$(docker ps | grep $1 | awk '{print $1}');
if [ -z $img ]; then
img=$(docker ps -a | grep $1 | awk '{print $1}') | head -1;
if [ -z $img ]; then
echo "Running a new container"
docker run ${AOSP_ARGS} ${=SSH_AUTH_ARGS} -v /home/mmaret/Project:/aosp/Project $1
else
echo "Starting $img"
docker start -i -a $img
fi
else
echo "Attach to $img"
docker exec -it $img /bin/bash
fi
}
_sdocker () {
local cur
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$(docker images | tail -n +2 | grep -v "<none>" | awk '{print $1}')" -- ${cur} ) )
}
complete -o default -F _sdocker sdocker