2024-01-25 15:00:44 +03:00
|
|
|
# Attach/create container box in current directory with specified name.
|
2024-01-31 17:47:55 +03:00
|
|
|
# By default uses current dir name.
|
2024-01-25 15:00:44 +03:00
|
|
|
# Usage: ca [NAME]
|
|
|
|
function ca() {
|
|
|
|
local name="${1}"
|
|
|
|
|
|
|
|
# Set default name.
|
2024-01-31 17:47:55 +03:00
|
|
|
# [[ "${name}" = "" ]] && name="main"
|
2024-01-31 18:40:02 +03:00
|
|
|
[[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}")
|
2024-01-25 15:00:44 +03:00
|
|
|
|
|
|
|
# Append box prefix.
|
|
|
|
name="box-${name}"
|
|
|
|
|
|
|
|
# Create container.
|
|
|
|
docker run \
|
|
|
|
--privileged \
|
|
|
|
-d -it \
|
2024-01-31 13:51:59 +03:00
|
|
|
-h "${HOSTNAME}${name#box}" --name "${name}" \
|
2024-01-25 15:00:44 +03:00
|
|
|
--workdir /data \
|
2024-01-30 00:09:24 +03:00
|
|
|
-e XDG_RUNTIME_DIR=/tmp \
|
|
|
|
-e WAYLAND_DISPLAY=${WAYLAND_DISPLAY} \
|
|
|
|
-v ${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}:/tmp/${WAYLAND_DISPLAY} \
|
2024-01-25 15:00:44 +03:00
|
|
|
-v ${PWD}:/data \
|
2024-01-25 15:08:17 +03:00
|
|
|
-v ${HOME}:/root \
|
2024-01-25 15:00:44 +03:00
|
|
|
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.
|
2024-01-31 18:25:30 +03:00
|
|
|
# By default uses current dir name.
|
2024-01-25 15:00:44 +03:00
|
|
|
# Usage: ck [NAME]
|
|
|
|
function ck() {
|
|
|
|
local name="${1}"
|
|
|
|
|
|
|
|
# Set default name.
|
2024-01-31 18:40:02 +03:00
|
|
|
[[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}")
|
2024-01-25 15:00:44 +03:00
|
|
|
|
|
|
|
# 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
|