Last active
December 24, 2024 21:33
-
-
Save rimelek/523f2cabb8b05bff89ae2304f20406fb to your computer and use it in GitHub Desktop.
Draw a christmas tree in Docker Desktop on the Containers tab and wish merry christmas in Hungarian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# English: https://gist.github.com/rimelek/3fe8a0bc8da72903824296835e9ae5dd | |
# Video: https://youtu.be/H2y7zkQpwvs | |
set -eu -o pipefail | |
tree_width=40 | |
tree_character="X" | |
tree_trunk_character="M" | |
# console chars | |
empty_character=".." | |
border_character="I" | |
console_width=$(( tree_width + 10 )) | |
console_height="12" | |
console_line_ids=() | |
console_line_number=1 | |
label="hu.rimelek.docker-christmas" | |
function console_render_line() { | |
local line="$1" | |
local delay_ms="${2:-300}" | |
local line_count="${#console_line_ids[@]}" | |
if (( line_count == console_height )); then | |
docker rm -f "${console_line_ids[0]}" | |
console_line_ids=("${console_line_ids[@]:1}") | |
fi | |
line="$(printf "%03d" $console_line_number)${empty_character}$line" | |
console_line_ids+=( | |
"$(docker create \ | |
--name "$line" \ | |
--label hu.rimelek.docker-christmas \ | |
bash)" | |
) | |
(( ++console_line_number )) | |
} | |
function console_padding() { | |
local text="$1" | |
local text_length="${#text}" | |
local align="${2:-right}" | |
local padding_size="$(( console_width - text_length ))" | |
case "$align" in | |
center) | |
local padding_left_size="$(( padding_size / 2 ))" | |
local padding_right_size="$(( console_width - (padding_left_size + text_length) ))" | |
if [[ "$padding_left_size" != "0" ]]; then | |
echo -n "$(printf -- "${empty_character}%.0s" $(seq 1 "$padding_left_size"))" | |
fi | |
echo -n "${text}" | |
if [[ "$padding_right_size" != "0" ]]; then | |
echo -n "$(printf -- "${empty_character}%.0s" $(seq 1 "$padding_right_size"))" | |
fi | |
;; | |
left) | |
if [[ "$padding_size" != "0" ]]; then | |
echo -n "$(printf -- "${empty_character}%.0s" $(seq 1 "$padding_size"))" | |
fi | |
echo -n "${text}" | |
;; | |
*) | |
echo -n "${text}" | |
if [[ "$padding_size" != "0" ]]; then | |
echo -n "$(printf -- "${empty_character}%.0s" $(seq 1 "$padding_size"))" | |
fi | |
;; | |
esac | |
} | |
function text_align() { | |
local text="${1:-}" | |
local align="${2:-left}" | |
local align_map | |
declare -A align_map | |
align_map["left"]=right | |
align_map["center"]=center | |
align_map["right"]=left | |
echo -n "$(console_padding "$text" "${align_map[$align]}")" | |
} | |
function console_writeln() { | |
local text="${1:-}" | |
local align="${2:-left}" | |
console_render_line "${border_character}$(text_align "$text" "$align")${border_character}" | |
} | |
function draw_tree_top() { | |
local number_start=1 | |
local number_end=$(( tree_width / 4 )) | |
local line_width | |
local i | |
i=$number_start | |
while (( i <= number_end )); do | |
line_width=$(( i * 4 )) | |
console_writeln "$(printf -- "${tree_character}%.0s" $(seq 1 $line_width))" "center" | |
sleep 0.2 | |
(( ++i )) | |
done | |
} | |
function draw_tree_bottom() { | |
local number_start=1 | |
local number_end=2 | |
local i | |
i=$number_start | |
while (( i <= number_end )); do | |
console_writeln "$(printf -- "${tree_trunk_character}%.0s" $(seq 1 4))" "center" | |
(( ++i )) | |
sleep 0.2 | |
done | |
} | |
function draw_merry_christmas() { | |
console_writeln "" | |
console_writeln "B_O_L_D_O_G__K_A_R_A_C_S_O_N_Y_T" "center" | |
console_writeln "D_O_C_K_E_R__F_E_L_H_A_S_Z_N_A_L_O_K" "center" | |
sleep 1 | |
console_writeln "V_A_G_Y" "center" | |
sleep 1 | |
console_writeln "C_S_A_K__N_A_G_Y_O_N__S_Z_E_P__N_A_P_O_T" "center" | |
console_writeln "" | |
sleep 3 | |
} | |
for i in $(seq 1 3); do | |
draw_tree_top | |
draw_tree_bottom | |
draw_merry_christmas | |
done | |
console_writeln "" | |
console_writeln "" | |
console_writeln "A_KONTENEREK__TORLODNEK" "center" | |
console_writeln "20__MASODPERC__MULVA" "center" | |
sleep 20 | |
docker container ls -a -q --filter label="$label" | xargs -- docker container rm -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment