# 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 "${name}" --name "${name}" \
--workdir /data \
-v ${PWD}:/data \
-v ${HOME}:/root \
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() {
# 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 boxes=$(docker ps -a | grep "box-" | sed -e "s/.*box-//")
[[ "${boxes[@]}" != "" ]] && echo "${boxes[@]}" || true
# Autocomplete with boxes.
function _comp_get_boxes() {
_autocomplete_first $(_get_boxes)
complete -F _comp_get_boxes ca ck