#!/usr/bin/env bash # D3Codex installer - put the `d3codex` terminal helper on your PATH. # # curl -fsSL https://d3codex.com/install.sh | bash # # Downloads https://d3codex.com/d3codex.sh into ~/.local/bin and, if that dir is # not already on your PATH, adds it to your shell startup file. No sudo, nothing # outside your home directory. Override the location with D3CODEX_BIN. # View this script first at https://d3codex.com/install.sh ; the tool: /cli/. set -euo pipefail SRC="${D3CODEX_SRC:-https://d3codex.com/d3codex.sh}" DIR="${D3CODEX_BIN:-$HOME/.local/bin}" mkdir -p "$DIR" curl -fsSL "$SRC" -o "$DIR/d3codex" chmod +x "$DIR/d3codex" echo "Installed: $DIR/d3codex" # Already on PATH? Then there is nothing else to do. case ":$PATH:" in *":$DIR:"*) echo "Ready. Try: d3codex myprogram.bp"; exit 0 ;; esac # Not on PATH: add it to the right shell startup file, once. LINE="export PATH=\"$DIR:\$PATH\"" case "${SHELL##*/}" in zsh) RC="$HOME/.zshrc" ;; bash) if [ -f "$HOME/.bash_profile" ]; then RC="$HOME/.bash_profile"; else RC="$HOME/.bashrc"; fi ;; *) RC="" ;; esac if [ -n "$RC" ]; then if ! grep -qsF "$DIR" "$RC"; then printf '\n# added by the D3Codex installer (https://d3codex.com/install.sh)\n%s\n' "$LINE" >> "$RC" echo "Added $DIR to your PATH in $RC" fi echo "Restart your terminal (or run: source \"$RC\"), then: d3codex myprogram.bp" else echo "Add this line to your shell startup file, then restart your terminal:" echo " $LINE" fi