Last active
May 19, 2026 10:51
-
-
Save Tuhaj/ddf00aa184f1d9edfc907f30c1533421 to your computer and use it in GitHub Desktop.
tadam — Windows TADAAAAM! shell command
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 | |
| # | |
| # tadam — installs a `tadam` shell command that plays the famous | |
| # Windows "TADAAAAM!" sound. 🎉 | |
| # | |
| # Install: | |
| # curl -sL https://gist.githubusercontent.com/Tuhaj/ddf00aa184f1d9edfc907f30c1533421/raw/install-tadam.sh | bash | |
| # | |
| # Uninstall: | |
| # curl -sL https://gist.githubusercontent.com/Tuhaj/ddf00aa184f1d9edfc907f30c1533421/raw/install-tadam.sh | bash -s -- --uninstall | |
| # | |
| # After installing, open a new terminal (or source your shell rc) and run: tadam | |
| # | |
| set -euo pipefail | |
| readonly VERSION="1.1.0" | |
| readonly SOUND_URL="https://raw.githubusercontent.com/MCPlayer2015/all-windows-sounds/main/(2001)%20Windows%20XP/tada.wav" | |
| readonly INSTALL_DIR="$HOME/.tadam" | |
| readonly SOUND_FILE="$INSTALL_DIR/tada.wav" | |
| readonly MARKER="# >>> tadam >>>" | |
| readonly MARKER_END="# <<< tadam <<<" | |
| # ── output helpers ────────────────────────────────────────────────────────── | |
| if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then | |
| BOLD=$'\033[1m'; DIM=$'\033[2m'; GREEN=$'\033[32m' | |
| RED=$'\033[31m'; CYAN=$'\033[36m'; RESET=$'\033[0m' | |
| else | |
| BOLD=''; DIM=''; GREEN=''; RED=''; CYAN=''; RESET='' | |
| fi | |
| step() { printf ' %s›%s %s\n' "$CYAN" "$RESET" "$*"; } | |
| ok() { printf ' %s✓%s %s\n' "$GREEN" "$RESET" "$*"; } | |
| warn() { printf ' %s!%s %s\n' "$RED" "$RESET" "$*" >&2; } | |
| die() { warn "$*"; exit 1; } | |
| banner() { | |
| printf '\n %s🎉 tadam%s %sv%s%s\n' "$BOLD" "$RESET" "$DIM" "$VERSION" "$RESET" | |
| printf ' %sthe famous Windows TADAAAAM! as a shell command%s\n\n' "$DIM" "$RESET" | |
| } | |
| cleanup() { [ -n "${TMP:-}" ] && rm -f "$TMP" 2>/dev/null || true; } | |
| trap cleanup EXIT | |
| trap 'warn "Aborted."; exit 130' INT | |
| # ── shell rc detection ────────────────────────────────────────────────────── | |
| detect_rc() { | |
| case "$(basename "${SHELL:-/bin/zsh}")" in | |
| zsh) printf '%s/.zshrc' "$HOME" ;; | |
| bash) printf '%s/.bashrc' "$HOME" ;; | |
| *) printf '%s/.profile' "$HOME" ;; | |
| esac | |
| } | |
| # remove any existing tadam block from a given rc file | |
| strip_block() { | |
| local rc="$1" | |
| [ -f "$rc" ] || return 0 | |
| if grep -qF "$MARKER" "$rc"; then | |
| local tmp; tmp="$(mktemp)" | |
| sed "/${MARKER}/,/${MARKER_END}/d" "$rc" > "$tmp" && mv "$tmp" "$rc" | |
| fi | |
| } | |
| # ── actions ───────────────────────────────────────────────────────────────── | |
| do_install() { | |
| banner | |
| local rc; rc="$(detect_rc)" | |
| local action="Installing" | |
| [ -f "$SOUND_FILE" ] && action="Updating" | |
| step "$action tadam into ${BOLD}${rc/#$HOME/~}${RESET}" | |
| command -v curl >/dev/null 2>&1 || die "curl is required but not found." | |
| # download to a temp file, then validate before committing | |
| mkdir -p "$INSTALL_DIR" | |
| TMP="$(mktemp)" | |
| curl -fsSL --retry 2 -o "$TMP" "$SOUND_URL" \ | |
| || die "Could not download the tada sound (network issue?)." | |
| [ -s "$TMP" ] || die "Downloaded file is empty." | |
| [ "$(head -c 4 "$TMP")" = "RIFF" ] || die "Downloaded file is not a valid WAV." | |
| mv "$TMP" "$SOUND_FILE"; TMP="" | |
| ok "Sound saved to ${SOUND_FILE/#$HOME/~}" | |
| # install (or refresh) the shell function, idempotently | |
| touch "$rc" | |
| strip_block "$rc" | |
| cat >> "$rc" <<EOF | |
| $MARKER v$VERSION | |
| # 🎉 TADAAAAM! — https://gist.github.com/Tuhaj/ddf00aa184f1d9edfc907f30c1533421 | |
| tadam() { | |
| local s="\$HOME/.tadam/tada.wav" | |
| [ -f "\$s" ] || { echo "tadam: sound not found at \$s" >&2; return 1; } | |
| if command -v afplay >/dev/null 2>&1; then afplay "\$s" | |
| elif command -v paplay >/dev/null 2>&1; then paplay "\$s" | |
| elif command -v aplay >/dev/null 2>&1; then aplay "\$s" | |
| elif command -v ffplay >/dev/null 2>&1; then ffplay -nodisp -autoexit -loglevel quiet "\$s" | |
| else echo "tadam: no audio player found (afplay/paplay/aplay/ffplay)" >&2; return 1 | |
| fi | |
| } | |
| $MARKER_END | |
| EOF | |
| ok "Added the ${BOLD}tadam${RESET} command to ${rc/#$HOME/~}" | |
| printf '\n %s🎉 Done!%s Start using it now with:\n\n' "$GREEN" "$RESET" | |
| printf ' source %s\n' "${rc/#$HOME/~}" | |
| printf ' tadam\n\n' | |
| } | |
| do_uninstall() { | |
| banner | |
| local rc; rc="$(detect_rc)" | |
| step "Removing tadam" | |
| strip_block "$rc" | |
| ok "Removed the tadam command from ${rc/#$HOME/~}" | |
| rm -rf "$INSTALL_DIR" | |
| ok "Deleted $INSTALL_DIR" | |
| printf '\n %sUninstalled.%s Restart your shell to finish.\n\n' "$DIM" "$RESET" | |
| } | |
| usage() { | |
| cat <<EOF | |
| tadam installer v$VERSION | |
| Usage: | |
| install-tadam.sh [--uninstall] [--help] | |
| Options: | |
| (no args) Install or update the tadam command. | |
| --uninstall Remove the tadam command and its sound file. | |
| --help Show this help. | |
| Honors NO_COLOR. | |
| EOF | |
| } | |
| # ── entrypoint ────────────────────────────────────────────────────────────── | |
| case "${1:-}" in | |
| "") do_install ;; | |
| --uninstall|-u) do_uninstall ;; | |
| --help|-h) usage ;; | |
| *) warn "Unknown option: $1"; echo; usage; exit 64 ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment