# Attach/create container box in current directory with specified name. # Uses `main` name by default. # Usage: ca [NAME] function ca() { local name="${1}" # Set default name. [[ "${name}" = "" ]] && name="main" # Append box prefix. name="box-${name}" # Create container. docker run \ --privileged \ -d -it \ -h "${HOSTNAME}${name#box}" --name "${name}" \ --workdir /data \ -e XDG_RUNTIME_DIR=/tmp \ -e WAYLAND_DISPLAY=${WAYLAND_DISPLAY} \ -v ${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}:/tmp/${WAYLAND_DISPLAY} \ -v ${PWD}:/data \ -v ${HOME}:/root \ -v /tmp/.X11-unix:/tmp/.X11-unix \ debian:latest bash -c bash &> /dev/null # Attempt to start container. docker start "${name}" &> /dev/null # Attach to running container. docker attach "${name}" } # Remove container box with specified name. # By default uses `main` name. # Usage: ck [NAME] function ck() { local name="${1}" # Set default name. [[ "${name}" = "" ]] && name="main" # Append box prefix. name="box-${name}" # Kill container. docker kill "${name}" &> /dev/null docker rm "${name}" &> /dev/null } # Remove all container boxes. function cka() { local IFS=$'\n' local boxes=$(_get_boxes) for box in ${boxes[@]}; do ck "${box}" done } # List all container boxes. function cl() { _get_boxes } # Print all boxes. function _get_boxes() { local IFS=$'\n' local boxes=$(docker ps -a | grep "box-" | sed -e "s/.*box-//") [[ "${boxes[@]}" != "" ]] && echo "${boxes[@]}" || true } # Autocomplete with boxes. function _comp_get_boxes() { local IFS=$'\n' _autocomplete_first $(_get_boxes) } complete -F _comp_get_boxes ca ck