Skip to content

Instantly share code, notes, and snippets.

@drunkhacker
Last active February 10, 2026 03:43
Show Gist options
  • Select an option

  • Save drunkhacker/ef6d45831648964282d9e237dde91566 to your computer and use it in GitHub Desktop.

Select an option

Save drunkhacker/ef6d45831648964282d9e237dde91566 to your computer and use it in GitHub Desktop.
mermaid-ascii installer for Claude Code
#!/usr/bin/env bash
#
# mermaid-ascii Installer for Claude Code
# One-liner: curl -fsSL https://gist.githubusercontent.com/drunkhacker/GIST_ID/raw/install.sh | bash
#
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# GitHub Release URL
RELEASE_BASE="https://github.com/drunkhacker/mermaid-ascii/releases/download/v0.1.0-br-support"
# Installation directories
BIN_DIR="${HOME}/.local/bin"
SKILL_DIR="${HOME}/.claude/skills/mermaid-ascii"
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[OK]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
# Detect OS
detect_os() {
case "$(uname -s)" in
Linux*) echo "Linux" ;;
Darwin*) echo "Darwin" ;;
MINGW*|MSYS*|CYGWIN*) echo "Windows" ;;
*) error "Unsupported OS: $(uname -s)" ;;
esac
}
# Detect architecture
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "x86_64" ;;
arm64|aarch64) echo "arm64" ;;
i386|i686) echo "i386" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
}
# Get the download filename based on OS and architecture
get_filename() {
local os=$1
local arch=$2
case "${os}" in
Linux|Darwin)
echo "mermaid-ascii_${os}_${arch}.tar.gz"
;;
Windows)
echo "mermaid-ascii_${os}_${arch}.zip"
;;
esac
}
# Install binary
install_binary() {
local os=$1
local arch=$2
local filename
filename=$(get_filename "$os" "$arch")
local url="${RELEASE_BASE}/${filename}"
local tmpdir
tmpdir=$(mktemp -d)
info "Downloading mermaid-ascii for ${os}/${arch}..."
if command -v curl &> /dev/null; then
curl -fsSL "$url" -o "${tmpdir}/${filename}"
elif command -v wget &> /dev/null; then
wget -q "$url" -O "${tmpdir}/${filename}"
else
error "Neither curl nor wget found. Please install one of them."
fi
info "Extracting..."
cd "$tmpdir"
if [[ "$filename" == *.tar.gz ]]; then
tar -xzf "$filename"
elif [[ "$filename" == *.zip ]]; then
unzip -q "$filename"
fi
# Create bin directory if it doesn't exist
mkdir -p "$BIN_DIR"
# Find and install the binary
local binary_name="mermaid-ascii"
[[ "$os" == "windows" ]] && binary_name="mermaid-ascii.exe"
if [[ -f "$binary_name" ]]; then
mv "$binary_name" "${BIN_DIR}/"
chmod +x "${BIN_DIR}/${binary_name}"
else
error "Binary not found in archive"
fi
# Cleanup
cd - > /dev/null
rm -rf "$tmpdir"
success "Binary installed to ${BIN_DIR}/mermaid-ascii"
}
# Install skill file
install_skill() {
info "Installing Claude Code skill..."
mkdir -p "$SKILL_DIR"
cat > "${SKILL_DIR}/SKILL.md" << 'SKILL_EOF'
---
name: mermaid-ascii
description: Render Mermaid diagrams as ASCII art in terminal
---
# Mermaid ASCII Rendering
When the user provides a Mermaid diagram, **immediately render it using `mermaid-ascii` and show ONLY the output**. Do NOT explain, interpret, or analyze the diagram - just show the rendered ASCII result.
## Instructions
1. Take the mermaid code exactly as provided
2. Run: `echo '<mermaid-code>' | mermaid-ascii -f -`
3. Display the output directly - no commentary before or after
## Options (use only if requested)
- `-a, --ascii` - Pure ASCII mode (no Unicode)
- `-x, --paddingX <n>` - Horizontal spacing (default: 5)
- `-y, --paddingY <n>` - Vertical spacing (default: 5)
## Example
User provides:
```
graph LR
A[Start] --> B[End]
```
You run the command and show ONLY the ASCII output. No explanation needed.
SKILL_EOF
success "Skill installed to ${SKILL_DIR}/SKILL.md"
}
# Check if PATH includes BIN_DIR
check_path() {
if [[ ":$PATH:" != *":${BIN_DIR}:"* ]]; then
warn "${BIN_DIR} is not in your PATH"
echo ""
echo "Add the following line to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo ""
echo -e " ${YELLOW}export PATH=\"\$HOME/.local/bin:\$PATH\"${NC}"
echo ""
echo "Then restart your shell or run: source ~/.bashrc (or ~/.zshrc)"
fi
}
# Main
main() {
echo ""
echo "======================================"
echo " mermaid-ascii Installer"
echo " for Claude Code"
echo "======================================"
echo ""
local os arch
os=$(detect_os)
arch=$(detect_arch)
info "Detected: ${os}/${arch}"
install_binary "$os" "$arch"
install_skill
echo ""
check_path
echo ""
echo "======================================"
success "Installation complete!"
echo "======================================"
echo ""
echo "Verify installation:"
echo " mermaid-ascii --help"
echo ""
echo "Use in Claude Code:"
echo " The /mermaid-ascii skill is now available"
echo ""
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment