#!/bin/sh set -eu SRC="${DUOTERM_SRC:-https://auto.relay70.dev/duoterm/duoterm.sh}" PREFIX="${DUOTERM_PREFIX:-$HOME/.local}" BINDIR="$PREFIX/bin" TARGET="$BINDIR/duoterm" MARKER="# >>> duoterm (claude account switch) >>>" MARKER_END="# <<< duoterm (claude account switch) <<<" say() { printf '%s\n' "$*"; } warn() { printf '%s\n' "$*" >&2; } die() { printf 'install: %s\n' "$*" >&2; exit 1; } command -v claude >/dev/null 2>&1 || warn "note: claude is not on PATH yet - duoterm will still install" fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" elif command -v wget >/dev/null 2>&1; then wget -qO- "$1" else die "neither curl nor wget is available" fi } mkdir -p "$BINDIR" || die "cannot create $BINDIR" tmp="$(mktemp "${TMPDIR:-/tmp}/duoterm.XXXXXX")" || die "cannot create a temp file" trap 'rm -f "$tmp"' EXIT INT TERM here="" case "$0" in */install.sh | install.sh) here="$(cd "$(dirname "$0")" && pwd)" ;; esac if [ -z "${DUOTERM_SRC:-}" ] && [ -n "$here" ] && [ -f "$here/duoterm.sh" ]; then SRC="$here/duoterm.sh" cp "$SRC" "$tmp" || die "cannot copy $SRC" else fetch "$SRC" > "$tmp" || die "download failed: $SRC" fi head -n 1 "$tmp" | grep -q '^#!' || die "downloaded file is not a script - refusing to install" grep -q 'DUOTERM_VERSION=' "$tmp" || die "downloaded file is not duoterm - refusing to install" mv "$tmp" "$TARGET" chmod 755 "$TARGET" trap - EXIT INT TERM VERSION="$("$TARGET" version 2>/dev/null || echo 'duoterm')" say "installed $VERSION -> $TARGET" wire_shell() { shell_name="$(basename "${SHELL:-/bin/zsh}")" case "$shell_name" in zsh) rc="$HOME/.zshrc"; kind=zsh ;; bash) if [ -f "$HOME/.bashrc" ]; then rc="$HOME/.bashrc"; else rc="$HOME/.bash_profile"; fi; kind=bash ;; fish) rc="$HOME/.config/fish/config.fish"; kind=fish; mkdir -p "$(dirname "$rc")" ;; *) warn "unrecognized shell: $shell_name - wire it by hand (see below)"; return 1 ;; esac if [ -f "$rc" ] && grep -qF "$MARKER" "$rc" 2>/dev/null; then say "shell wrapper already present in $rc" return 0 fi { printf '\n%s\n' "$MARKER" printf 'eval "$(%s shell %s)"\n' "$TARGET" "$kind" printf '%s\n' "$MARKER_END" } >> "$rc" say "wired the claude wrapper into $rc" WIRED_RC="$rc" return 0 } WIRED_RC="" if [ "${DUOTERM_NO_WIRE:-0}" = "1" ]; then say "skipped shell wiring (DUOTERM_NO_WIRE=1)" else wire_shell || true fi case ":$PATH:" in *":$BINDIR:"*) ;; *) warn "" warn "$BINDIR is not on your PATH. Add this to your shell startup file:" warn " export PATH=\"$BINDIR:\$PATH\"" ;; esac cat <