Skip to content

Commit 6e85e34

Browse files
committed
[YADM] Make the YADM banner more colorful
This adds some helper functions to pick four random ANSI color codes and use one for each letter in the YADM banner that gets printed out each time the bootstrap script is run.
1 parent 90ed8fc commit 6e85e34

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

.config/yadm/bootstrap

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,52 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
RED='\033[0;31m'
44
NC='\033[0m'
55

66
# Generated using
77
# https://textkool.com/en/ascii-art-generator?hl=default&vl=default&font=DOS%20Rebel&text=YADM%20bootstrap
8-
cat <<EOF
9-
10-
█████ █████ █████████ ██████████ ██████ ██████
11-
░░███ ░░███ ███░░░░░███ ░░███░░░░███ ░░██████ ██████
12-
░░███ ███ ░███ ░███ ░███ ░░███ ░███░█████░███
13-
░░█████ ░███████████ ░███ ░███ ░███░░███ ░███
14-
░░███ ░███░░░░░███ ░███ ░███ ░███ ░░░ ░███
15-
░███ ░███ ░███ ░███ ███ ░███ ░███
16-
█████ █████ █████ ██████████ █████ █████
17-
░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░
18-
19-
EOF
8+
9+
# Select 4 unique random colors for the banner letters (Y, A, D, M)
10+
COLORS=(31 32 33 34 35 36 37 91 92 93 94 95 96 97)
11+
for i in 0 1 2 3; do
12+
j=$((i + RANDOM % (${#COLORS[@]} - i)))
13+
tmp=${COLORS[i]}
14+
COLORS[i]=${COLORS[j]}
15+
COLORS[j]=$tmp
16+
done
17+
ESC=$'\033'
18+
C_Y="${ESC}[${COLORS[0]}m"; C_A="${ESC}[${COLORS[1]}m"
19+
C_D="${ESC}[${COLORS[2]}m"; C_M="${ESC}[${COLORS[3]}m"
20+
RST="${ESC}[0m"
21+
22+
# Colorize only the █ characters in the string.
23+
color_blocks() {
24+
printf '%s' "$1" | sed "s/█/$2$RST/g"
25+
}
26+
27+
print_banner_line() {
28+
local line="$1"
29+
local y_part="${line:0:12}"
30+
local a_part="${line:12:14}"
31+
local d_part="${line:26:13}"
32+
local m_part="${line:39}"
33+
printf '%s%s%s%s\n' \
34+
"$(color_blocks "$y_part" "$C_Y")" \
35+
"$(color_blocks "$a_part" "$C_A")" \
36+
"$(color_blocks "$d_part" "$C_D")" \
37+
"$(color_blocks "$m_part" "$C_M")"
38+
}
39+
40+
echo ""
41+
print_banner_line " █████ █████ █████████ ██████████ ██████ ██████"
42+
print_banner_line "░░███ ░░███ ███░░░░░███ ░░███░░░░███ ░░██████ ██████ "
43+
print_banner_line " ░░███ ███ ░███ ░███ ░███ ░░███ ░███░█████░███ "
44+
print_banner_line " ░░█████ ░███████████ ░███ ░███ ░███░░███ ░███ "
45+
print_banner_line " ░░███ ░███░░░░░███ ░███ ░███ ░███ ░░░ ░███ "
46+
print_banner_line " ░███ ░███ ░███ ░███ ███ ░███ ░███ "
47+
print_banner_line " █████ █████ █████ ██████████ █████ █████"
48+
print_banner_line " ░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░ "
49+
echo ""
2050

2151
if ! command -v brew >/dev/null 2>&1; then
2252
echo "Installing Homebrew. If it appears stuck, press Enter."

0 commit comments

Comments
 (0)