-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
140 lines (125 loc) Β· 5.38 KB
/
Copy pathinstall.sh
File metadata and controls
140 lines (125 loc) Β· 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
set -euo pipefail
# mimicode installer (macOS & Linux)
#
# Downloads a prebuilt mimicode binary (no Go toolchain required) and installs
# it to ~/.local/bin, then adds that directory to your PATH via the correct
# profile file for your shell (zsh, bash, or fish).
#
# Quick install:
# curl -fsSL https://raw.githubusercontent.com/trymimicode/mimicode-go/main/install.sh | bash
#
# Overrides:
# INSTALL_DIR=$HOME/bin ... install location (default: ~/.local/bin)
# MIMICODE_BASE_URL=... release download base (used by CI tests)
REPO="trymimicode/mimicode-go"
BINARY_NAME="mimicode"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
BASE_URL="${MIMICODE_BASE_URL:-https://github.com/$REPO/releases/latest/download}"
echo "π Installing mimicode..."
# ββ Detect OS / architecture βββββββββββββββββββββββββββββββββββββββββββββββββ
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) OS="linux" ;;
Darwin) OS="darwin" ;;
*) echo "β Unsupported OS: $OS"; exit 1 ;;
esac
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) echo "β Unsupported architecture: $ARCH"; exit 1 ;;
esac
# ββ Download the prebuilt binary βββββββββββββββββββββββββββββββββββββββββββββ
BINARY_FILE="$BINARY_NAME-$OS-$ARCH"
DOWNLOAD_URL="$BASE_URL/$BINARY_FILE"
TMP_BIN="$(mktemp)"
trap 'rm -f "$TMP_BIN"' EXIT
echo " Downloading $BINARY_FILE..."
if command -v curl >/dev/null 2>&1; then
HTTP_CODE="$(curl -fL -w '%{http_code}' -o "$TMP_BIN" "$DOWNLOAD_URL" 2>/dev/null || echo 000)"
elif command -v wget >/dev/null 2>&1; then
if wget -qO "$TMP_BIN" "$DOWNLOAD_URL"; then HTTP_CODE="200"; else HTTP_CODE="000"; fi
else
echo "β Need curl or wget to download mimicode."; exit 1
fi
if [ "$HTTP_CODE" != "200" ] || [ ! -s "$TMP_BIN" ]; then
echo "β Could not download a prebuilt binary for $OS/$ARCH (HTTP $HTTP_CODE)."
echo " Check available downloads at https://github.com/$REPO/releases"
exit 1
fi
# ββ Install ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
mkdir -p "$INSTALL_DIR"
mv -f "$TMP_BIN" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
trap - EXIT
echo "β $BINARY_NAME installed to $INSTALL_DIR/$BINARY_NAME"
# ββ Add INSTALL_DIR to PATH using the right profile for the active shell ββββββ
add_to_path() {
# Already reachable in this session β nothing to wire up.
case ":$PATH:" in
*":$INSTALL_DIR:"*) return 0 ;;
esac
local shell_name profile line
shell_name="$(basename "${SHELL:-sh}")"
case "$shell_name" in
zsh)
profile="${ZDOTDIR:-$HOME}/.zshrc"
line="export PATH=\"$INSTALL_DIR:\$PATH\""
;;
bash)
# macOS login shells read .bash_profile; Linux uses .bashrc.
if [ "$OS" = "darwin" ]; then profile="$HOME/.bash_profile"; else profile="$HOME/.bashrc"; fi
line="export PATH=\"$INSTALL_DIR:\$PATH\""
;;
fish)
profile="$HOME/.config/fish/config.fish"
line="fish_add_path \"$INSTALL_DIR\""
mkdir -p "$(dirname "$profile")"
;;
*)
profile="$HOME/.profile"
line="export PATH=\"$INSTALL_DIR:\$PATH\""
;;
esac
touch "$profile"
if grep -qF "$INSTALL_DIR" "$profile" 2>/dev/null; then
echo "β PATH entry already present in $profile"
else
printf '\n# Added by mimicode installer\n%s\n' "$line" >> "$profile"
echo "β Added $INSTALL_DIR to PATH in $profile"
fi
echo " Restart your shell or run: source \"$profile\""
}
add_to_path
# ββ Verify βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
if ! "$INSTALL_DIR/$BINARY_NAME" --version >/dev/null 2>&1; then
echo "β οΈ Installed but '$BINARY_NAME --version' failed β check the output above."
fi
# ββ Dependency / environment checks ββββββββββββββββββββββββββββββββββββββββββ
if ! command -v rg >/dev/null 2>&1; then
echo ""
echo "β οΈ ripgrep (rg) is required but not installed."
case "$OS" in
darwin) echo " Install: brew install ripgrep" ;;
linux) echo " Install: sudo apt install ripgrep # Debian/Ubuntu"
echo " sudo dnf install ripgrep # Fedora" ;;
esac
fi
if [ -z "${ANTHROPIC_API_KEY:-}" ]; then
echo ""
echo "β οΈ ANTHROPIC_API_KEY not set."
echo " Get a key at https://console.anthropic.com/settings/keys then run:"
echo " $BINARY_NAME key --set your-key-here"
echo " or set it in your shell:"
echo " export ANTHROPIC_API_KEY=\"your-key-here\""
fi
echo ""
echo "β
Installation complete!"
echo ""
echo "Usage:"
echo " $BINARY_NAME \"add tests to calc.go\""
echo " $BINARY_NAME --tui"
echo " $BINARY_NAME -s myfeature \"continue working\""
echo ""
echo "Docs: https://github.com/$REPO"