#!/usr/bin/env bash
# cliscrpy installer — by @nerdcuba · MIT License
set -e
BIN="$HOME/.local/bin"; APP="$HOME/.local/share/applications"
ICONS="$HOME/.local/share/icons/hicolor/scalable/apps"
URL="https://raw.githubusercontent.com/nerdcuba/cliscrpy/main/cliscrpy"
mkdir -p "$BIN"
# Use the local copy only when running from a checkout of this repo.
# With `curl ... | bash`, $0 is "bash", so never trust whatever "cliscrpy" sits in the current dir.
SELF=""
case "$0" in */install.sh|install.sh) SELF="$(cd "$(dirname "$0")" 2>/dev/null && pwd)/cliscrpy";; esac
if [ -n "$SELF" ] && [ -f "$SELF" ] && head -n 3 "$SELF" | grep -q '^# cliscrpy'; then
cp "$SELF" "$BIN/cliscrpy"
else
curl -fsSL "$URL" -o "$BIN/cliscrpy"
fi
chmod +x "$BIN/cliscrpy"
# Shell completions (generated by cliscrpy itself; skipped silently if it can't run yet)
completions() {
local out
if out=$("$BIN/cliscrpy" completion fish 2>/dev/null) && { command -v fish >/dev/null || [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/fish" ]; }; then
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/fish/completions"
printf '%s\n' "$out" > "${XDG_CONFIG_HOME:-$HOME/.config}/fish/completions/cliscrpy.fish" && echo "✔ fish completions"
fi
if out=$("$BIN/cliscrpy" completion bash 2>/dev/null); then
mkdir -p "$HOME/.local/share/bash-completion/completions"
printf '%s\n' "$out" > "$HOME/.local/share/bash-completion/completions/cliscrpy" && echo "✔ bash completions"
fi
if command -v zsh >/dev/null && out=$("$BIN/cliscrpy" completion zsh 2>/dev/null); then
mkdir -p "$HOME/.local/share/zsh/site-functions"
printf '%s\n' "$out" > "$HOME/.local/share/zsh/site-functions/_cliscrpy" && echo "✔ zsh completions"
echo " (zsh: add fpath=(~/.local/share/zsh/site-functions \$fpath) before compinit in ~/.zshrc)"
fi
}
completions
# macOS has no .desktop launchers: stop here
if [ "$(uname -s)" = Darwin ]; then
echo "✔ cliscrpy installed to $BIN/cliscrpy"
case ":$PATH:" in *":$BIN:"*) ;; *) echo "! Add to PATH: export PATH=\"$BIN:\$PATH\"";; esac
bash -c '[ "${BASH_VERSINFO[0]}" -ge 5 ]' 2>/dev/null || [ -x /opt/homebrew/bin/bash ] || [ -x /usr/local/bin/bash ] || \
echo "! cliscrpy needs a newer bash: brew install bash"
echo " Run: cliscrpy help"; exit 0
fi
# Ship our own icon so the launcher never depends on the icon theme
mkdir -p "$APP" "$ICONS"
cat > "$ICONS/cliscrpy.svg" <<'SVG'
SVG
command -v gtk-update-icon-cache >/dev/null && gtk-update-icon-cache -q -t "$HOME/.local/share/icons/hicolor" 2>/dev/null || true
cat > "$APP/cliscrpy.desktop" <