Created
October 18, 2026 12:48
-
-
Save friz-xc/b74fb37152b3348bda3add9426289529 to your computer and use it in GitHub Desktop.
pd-scripts: download pd-scripts
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 | |
| # alias: `n/a` | |
| # desc: download pd-scripts to ~/pd-scripts and install its commands. Sets up | |
| # the Mac tools first (developer tools, gh, GitHub login) if they're missing. | |
| # usage: /bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/friz-xc/b74fb37152b3348bda3add9426289529/raw/pd-scripts-clone.sh)" | |
| # Standalone on purpose: it's published as a public gist and runs before | |
| # pd-scripts exists, so it can't source git-utils.sh. | |
| set -euo pipefail | |
| declare -r PD_SCRIPTS_URL="https://github.com/friz-xc/pd-scripts.git" | |
| declare -r PD_SCRIPTS_DIR="$HOME/pd-scripts" | |
| declare -r PREREQUISITES_URL="https://gist.githubusercontent.com/friz-xc/49f6d0dcfa22173ec33d02e172b7df37/raw/prerequisites-setup.sh" | |
| green() { echo -e "\033[32m$*\033[0m"; } | |
| red() { echo -e "\033[31m$*\033[0m"; } | |
| dim() { echo -e "\033[2m$*\033[0m"; } | |
| bold() { echo -e "\033[1m$*\033[0m"; } | |
| fn_fail() { | |
| red "✖ $1" >&2 | |
| [[ -n "${2:-}" ]] && dim "$2" >&2 | |
| dim "Nothing is broken. Fix the above and run the same command again." >&2 | |
| exit 1 | |
| } | |
| # git comes with the developer tools, and gh must be logged in so git never | |
| # asks for a password; run the prerequisites setup if either is missing. | |
| fn_ensure_prerequisites() { | |
| export PATH="$HOME/.local/bin:$PATH" | |
| if xcode-select -p >/dev/null 2>&1 && | |
| command -v gh >/dev/null 2>&1 && | |
| gh auth status --hostname github.com >/dev/null 2>&1; then | |
| return | |
| fi | |
| bold "Your Mac needs a few tools first." | |
| local script | |
| script=$(curl -fsSL "$PREREQUISITES_URL") || | |
| fn_fail "Couldn't download the Mac setup." "Check your internet connection." | |
| /bin/bash -c "$script" | |
| echo | |
| } | |
| fn_pd_scripts_clone() { | |
| [[ "$(uname)" == "Darwin" ]] || fn_fail "This setup is for Macs only." | |
| fn_ensure_prerequisites | |
| gh auth setup-git --hostname github.com >/dev/null 2>&1 || true | |
| bold "Downloading pd-scripts" | |
| export GIT_TERMINAL_PROMPT=0 | |
| if [[ -d "$PD_SCRIPTS_DIR/.git" ]]; then | |
| green "✔ Already downloaded: ${PD_SCRIPTS_DIR}" | |
| elif [[ -e "$PD_SCRIPTS_DIR" ]]; then | |
| fn_fail "\`${PD_SCRIPTS_DIR}\` already exists and isn't pd-scripts." "Ask an engineer for help." | |
| else | |
| local out | |
| out=$(git clone --quiet "$PD_SCRIPTS_URL" "$PD_SCRIPTS_DIR" 2>&1) || | |
| fn_fail "Couldn't download pd-scripts." \ | |
| "If it says \"Repository not found\", ask an engineer to give your GitHub | |
| account access to pd-scripts (friz-xc/pd-scripts). | |
| ${out}" | |
| green "✔ Downloaded to ${PD_SCRIPTS_DIR}" | |
| fi | |
| "$PD_SCRIPTS_DIR/install.sh" >/dev/null || | |
| fn_fail "Downloaded, but couldn't install the commands." "Ask an engineer for help." | |
| echo | |
| green "✔ All done. pd-scripts is ready." | |
| dim " Open a new Terminal window to use its commands, e.g. \`second-brain-clone\`." | |
| } | |
| # runs from `bash -c "$(curl …)"`, where there's no BASH_SOURCE to guard on | |
| fn_pd_scripts_clone "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment