Add ANSI color and styling to shell scripts

This commit is contained in:
Chris Wanstrath 2026-03-08 22:18:53 -07:00
parent 98c09dd843
commit 0aa375f037
4 changed files with 81 additions and 18 deletions

45
color-preview.sh Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
b=$'\033[1m' d=$'\033[2m' g=$'\033[32m' c=$'\033[36m' y=$'\033[33m' r=$'\033[0m'
echo ""
echo " ┌── CLI installer (curl | bash) ──────────────┐"
echo ""
echo " ${b}🐾 toes cli${r}"
echo " ${d}─────────────────────────────${r}"
echo ""
echo " ${d}Fetching macos/arm64...${r}"
echo " ${g}Installed to${r} ${b}/Users/chris/.local/bin/toes${r}"
echo ""
echo " ${y}Add /Users/chris/.local/bin to your \$PATH, then:${r}"
echo " Run ${c}toes${r} to get started."
echo ""
echo ""
echo " ┌── After deploy ─────────────────────────────┐"
echo ""
echo " ${b}${g}🐾 Deployed${r} to ${b}pi@toes.local${r}"
echo " ${d}─────────────────────────────${r}"
echo ""
echo " Dashboard: ${c}http://toes.local${r}"
echo ""
echo " ${d}Grab the CLI:${r}"
echo " ${c}curl -fsSL http://toes.local/install | bash${r}"
echo ""
echo ""
echo " ┌── After server install ─────────────────────┐"
echo ""
echo " ${d}╔══════════════════════════════════╗${r}"
echo " ${d}${r} ${b}🐾 toes${r} ${d}- personal web appliance ║${r}"
echo " ${d}╚══════════════════════════════════╝${r}"
echo ""
echo " ${d}>>${r} Updating system packages"
echo " ${d}>>${r} Installing bun"
echo " ${d}>>${r} Building"
echo ""
echo " ${b}${g}🐾 toes abc1234 is up!${r}"
echo " ${d}─────────────────────────────${r}"
echo ""
echo " Dashboard: ${c}http://toes.local${r}"
echo ""
echo " ${d}Grab the CLI:${r}"
echo " ${c}curl -fsSL http://toes.local/install | bash${r}"
echo ""

View File

@ -15,18 +15,20 @@ DATA_DIR=~/data
# ── Helpers ────────────────────────────────────────────── # ── Helpers ──────────────────────────────────────────────
b=$'\033[1m' d=$'\033[2m' g=$'\033[32m' c=$'\033[36m' y=$'\033[33m' r=$'\033[0m'
quiet() { "$@" > /dev/null 2>&1; } quiet() { "$@" > /dev/null 2>&1; }
info() { echo ">> $1"; } info() { echo " ${d}>>${r} $1"; }
fail() { echo "ERROR: $1" >&2; exit 1; } fail() { echo " ${y}ERROR:${r} $1" >&2; exit 1; }
# ── Preflight ──────────────────────────────────────────── # ── Preflight ────────────────────────────────────────────
echo "" echo ""
echo " ╔══════════════════════════════════╗" echo " ${d}╔══════════════════════════════════╗${r}"
echo " ║ 🐾 toes - personal web appliance ║" echo " ${d}${r} ${b}🐾 toes${r} ${d}- personal web appliance ║${r}"
echo " ╚══════════════════════════════════╝" echo " ${d}╚══════════════════════════════════╝${r}"
echo "" echo ""
[ "$(whoami)" = "toes" ] || fail "Must be run as the 'toes' user." [ "$(whoami)" = "toes" ] || fail "Must be run as the 'toes' user."
@ -125,9 +127,11 @@ sudo systemctl restart toes
VERSION=$(git describe --tags --always 2>/dev/null || echo "unknown") VERSION=$(git describe --tags --always 2>/dev/null || echo "unknown")
echo "" echo ""
echo " toes $VERSION is running!" echo " ${b}${g}🐾 toes $VERSION is up!${r}"
echo " http://$(hostname).local" echo " ${d}─────────────────────────────${r}"
echo "" echo ""
echo " Install the CLI on your local machine:" echo " Dashboard: ${c}http://$(hostname).local${r}"
echo " curl -fsSL http://$(hostname).local/install | bash" echo ""
echo " ${d}Grab the CLI:${r}"
echo " ${c}curl -fsSL http://$(hostname).local/install | bash${r}"
echo "" echo ""

View File

@ -57,9 +57,14 @@ done
sudo systemctl restart toes.service sudo systemctl restart toes.service
SCRIPT SCRIPT
echo "=> Deployed to $SSH_HOST" b=$'\033[1m' d=$'\033[2m' g=$'\033[32m' c=$'\033[36m' r=$'\033[0m'
echo "=> Visit $URL"
echo "" echo ""
echo " Install the CLI on your local machine:" echo " ${b}${g}🐾 Deployed${r} to ${b}$SSH_HOST${r}"
echo " curl -fsSL $URL/install | bash" echo " ${d}─────────────────────────────${r}"
echo ""
echo " Dashboard: ${c}$URL${r}"
echo ""
echo " ${d}Grab the CLI:${r}"
echo " ${c}curl -fsSL $URL/install | bash${r}"
echo "" echo ""

View File

@ -1,19 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
b=$'\033[1m' d=$'\033[2m' g=$'\033[32m' c=$'\033[36m' y=$'\033[33m' r=$'\033[0m'
OS=$(uname -s | tr '[:upper:]' '[:lower:]') OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m) ARCH=$(uname -m)
case "$OS" in case "$OS" in
darwin) OS=macos ;; darwin) OS=macos ;;
linux) OS=linux ;; linux) OS=linux ;;
*) echo "🐾 Unsupported OS: $OS" >&2; exit 1 ;; *) echo "${y}Unsupported OS: $OS${r}" >&2; exit 1 ;;
esac esac
case "$ARCH" in case "$ARCH" in
x86_64) ARCH=x64 ;; x86_64) ARCH=x64 ;;
arm64|aarch64) ARCH=arm64 ;; arm64|aarch64) ARCH=arm64 ;;
*) echo "🐾 Unsupported arch: $ARCH" >&2; exit 1 ;; *) echo "${y}Unsupported arch: $ARCH${r}" >&2; exit 1 ;;
esac esac
BINARY="toes-${OS}-${ARCH}" BINARY="toes-${OS}-${ARCH}"
@ -28,11 +30,18 @@ else
fi fi
mkdir -p "$INSTALL_DIR" mkdir -p "$INSTALL_DIR"
echo "🐾 Downloading toes CLI (${OS}/${ARCH})..." echo ""
echo " ${b}🐾 toes cli${r}"
echo " ${d}─────────────────────────────${r}"
echo ""
echo " ${d}Fetching ${OS}/${ARCH}...${r}"
curl -fsSL "$URL" -o "$INSTALL_DIR/toes" curl -fsSL "$URL" -o "$INSTALL_DIR/toes"
chmod +x "$INSTALL_DIR/toes" chmod +x "$INSTALL_DIR/toes"
echo "🐾 Installed toes to $INSTALL_DIR/toes" echo " ${g}Installed to${r} ${b}$INSTALL_DIR/toes${r}"
echo ""
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
echo "🐾 Add $INSTALL_DIR to your PATH to use toes globally" echo " ${y}Add $INSTALL_DIR to your \$PATH, then:${r}"
fi fi
echo " Run ${c}toes${r} to get started."
echo ""