feat: reworked dev container script, many more features

This commit is contained in:
2026-07-24 13:42:20 +02:00
parent 90bc568a06
commit 62de408edd
2 changed files with 52 additions and 12 deletions
+49 -10
View File
@@ -5,7 +5,7 @@ mount_path=$(pwd)
if [[ -n "$2" ]]; then if [[ -n "$2" ]]; then
name=$2 name=$2
else else
name=$(pwd | rev | cut -d "/" -f 1 | rev) name=$(pwd | rev | cut -d "/" -f 1-2 | rev | sed -e 's/\//-/')
fi fi
if [[ $1 == "help" ]]; then if [[ $1 == "help" ]]; then
@@ -25,26 +25,65 @@ rm removes the container for the current directory if provided name is existing
exit 0 exit 0
fi fi
echo "
janishutz dev containers
"
if [[ $(systemctl is-active docker) != "active" ]]; then if [[ $(systemctl is-active docker) != "active" ]]; then
echo " echo "
Docker daemon not running, starting with systemctl -> Docker daemon not running, starting with systemctl <-
" "
sudo systemctl start docker sudo systemctl start docker
fi fi
if [[ $1 == "rm" ]]; then if [[ $1 == "rm" ]]; then
echo " echo "
janishutz dev containers -> Removing containers with $name in their name <-
-> Removing container $name <-
" "
docker stop $name if [[ $(read -p "Do you really want to delete ALL containers for this directory? (y/N) " response && echo $response) == 'y' ]]; then
docker container rm $name for container in $(docker container ls -aq -f name=$name); do
docker stop $container
docker container rm $container
done
else
echo "Aborting."
exit 0
fi
elif [[ $1 == "shell" ]]; then
containers=$(docker ps -q -f name=$name)
count=$((${#containers[@]}))
if [[ ${containers[0]} == "" ]]; then
count=$(($count-1))
fi
if [[ $count == 0 ]]; then
echo "
-> No suitable running container found. Aborting.
"
elif [[ $count == 1 ]]; then
echo "
-> Connecting to running container ${containers[0]}
"
docker exec -it ${containers[0]} '/bin/bash'
else
echo "
-> Multiple possible containers found to attach to. Pick one (enter number)
"
docker ps -f name=$name
read -p "Enter number (1-$(${#containers[@]})) " sel
docker exec -it containers[$sel] '/bin/bash'
fi
else
name=$name-$1
if [[ $(docker container ls -aq -f name=$name) != "" ]]; then
echo "
-> Starting existing container $name <-
"
docker start -i $name
else else
echo " echo "
janishutz dev containers
-> Creating container $name <- -> Creating container $name <-
" "
eval "${base_path}$1-container $1-$name $mount_path" eval "${base_path}$1-container $name $mount_path"
fi
fi fi
+2 -1
View File
@@ -1,3 +1,4 @@
complete -a "base node php python torch-rocm vue webserver" -c dev-containers -f complete -a "base jupyter node php python torch-rocm vue webserver" -c dev-containers -f
complete -a "rm" -d "Delete the container for this folder" -c dev-containers -f complete -a "rm" -d "Delete the container for this folder" -c dev-containers -f
complete -a "help" -d "Show help" -c dev-containers -f complete -a "help" -d "Show help" -c dev-containers -f
complete -a "shell" -d "Create an extra shell for the currently running container" -c dev-containers -f