-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
246 lines (211 loc) · 7.03 KB
/
Copy pathinstall.sh
File metadata and controls
246 lines (211 loc) · 7.03 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env bash
#
# Wiggly Installer
# ================
# This script downloads and installs the latest release of wiggly.
#
# Usage:
# curl -sSL https://raw.githubusercontent.com/nitodeco/wiggly/main/install.sh | bash
#
# What it does:
# 1. Detects your OS (macOS or Linux) and CPU architecture (Intel or ARM)
# 2. Fetches the latest release version from GitHub
# 3. Downloads the correct pre-built binary for your platform
# 4. Installs it to ~/.local/bin
# 5. Adds ~/.local/bin to your PATH if needed
#
# Supported platforms:
# - macOS (Intel x86_64)
# - macOS (Apple Silicon arm64)
# - Linux (x86_64)
#
set -euo pipefail
REPO="nitodeco/wiggly"
INSTALL_DIR="${HOME}/.local/bin"
TEMP_DIR=""
# Determines which binary to download based on OS and CPU architecture
detect_platform() {
local os arch target
os=$(uname -s)
arch=$(uname -m)
case "${os}" in
Darwin)
case "${arch}" in
x86_64) target="x86_64-apple-darwin" ;;
arm64) target="aarch64-apple-darwin" ;;
*) echo "Unsupported architecture: ${arch}" >&2; exit 1 ;;
esac
;;
Linux)
case "${arch}" in
x86_64) target="x86_64-unknown-linux-gnu" ;;
*) echo "Unsupported architecture: ${arch}" >&2; exit 1 ;;
esac
;;
*)
echo "Unsupported OS: ${os}" >&2
exit 1
;;
esac
echo "${target}"
}
# Queries GitHub API to find the most recent release tag (e.g., "v0.1.0")
get_latest_version() {
curl -sS "https://api.github.com/repos/${REPO}/releases/latest" | \
grep '"tag_name":' | \
sed -E 's/.*"([^"]+)".*/\1/'
}
# Adds ~/.local/bin to PATH in the user's shell config file
configure_path() {
local shell_name config_file path_line
shell_name=$(basename "${SHELL}")
case "${shell_name}" in
bash)
config_file="${HOME}/.bashrc"
path_line="export PATH=\"\${HOME}/.local/bin:\${PATH}\""
;;
zsh)
config_file="${HOME}/.zshrc"
path_line="export PATH=\"\${HOME}/.local/bin:\${PATH}\""
;;
fish)
config_file="${HOME}/.config/fish/config.fish"
path_line="fish_add_path ${HOME}/.local/bin"
;;
*)
echo "Unknown shell: ${shell_name}. Please add ${INSTALL_DIR} to your PATH manually."
return
;;
esac
# Check if PATH line already exists in config
if [[ -f "${config_file}" ]] && grep -q ".local/bin" "${config_file}"; then
echo "PATH already configured in ${config_file}"
return
fi
# Create config file if it doesn't exist (mainly for fish)
mkdir -p "$(dirname "${config_file}")"
echo "" >> "${config_file}"
echo "# Added by wiggly installer" >> "${config_file}"
echo "${path_line}" >> "${config_file}"
echo "Added ${INSTALL_DIR} to PATH in ${config_file}"
echo "Run 'source ${config_file}' or restart your shell to use wiggly"
}
register_macos_shortcut() {
local shortcut_name unsigned_shortcut signed_shortcut
if [[ "$(uname -s)" != "Darwin" ]]; then
return
fi
shortcut_name="wiggly"
if ! command -v shortcuts >/dev/null 2>&1; then
echo "macOS Shortcuts CLI not found; skipping shortcut setup."
return
fi
if ! command -v plutil >/dev/null 2>&1; then
echo "macOS plutil not found; skipping shortcut setup."
return
fi
if shortcuts list 2>/dev/null | grep -Fxq "${shortcut_name}"; then
echo "macOS shortcut '${shortcut_name}' is already installed."
return
fi
unsigned_shortcut="${TEMP_DIR}/${shortcut_name}.shortcut"
signed_shortcut="${TEMP_DIR}/${shortcut_name} Signed.shortcut"
cat > "${unsigned_shortcut}" <<'SHORTCUT_PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>WFWorkflowActions</key>
<array>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.runshellscript</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFPassInput</key>
<false/>
<key>WFScript</key>
<string><![CDATA[binary_path="${HOME}/.local/bin/wiggly"
escaped_binary_path=$(printf "%q" "${binary_path}")
osascript <<APPLESCRIPT
tell application "Terminal"
activate
do script "${escaped_binary_path}"
end tell
APPLESCRIPT
]]></string>
<key>WFShell</key>
<string>/bin/bash</string>
</dict>
</dict>
</array>
<key>WFWorkflowClientVersion</key>
<string>2600.0.5</string>
<key>WFWorkflowIcon</key>
<dict>
<key>WFWorkflowIconGlyphNumber</key>
<integer>61440</integer>
<key>WFWorkflowIconStartColor</key>
<integer>4251333119</integer>
</dict>
<key>WFWorkflowInputContentItemClasses</key>
<array/>
<key>WFWorkflowMinimumClientVersion</key>
<integer>900</integer>
<key>WFWorkflowMinimumClientVersionString</key>
<string>900</string>
<key>WFWorkflowName</key>
<string>wiggly</string>
<key>WFWorkflowOutputContentItemClasses</key>
<array/>
<key>WFWorkflowTypes</key>
<array>
<string>MenuBar</string>
<string>QuickActions</string>
</array>
</dict>
</plist>
SHORTCUT_PLIST
plutil -convert binary1 "${unsigned_shortcut}"
if shortcuts sign --mode anyone --input "${unsigned_shortcut}" --output "${signed_shortcut}" >/dev/null 2>&1; then
open "${signed_shortcut}"
echo "Opened the '${shortcut_name}' shortcut import."
echo "Click 'Add Shortcut', then add a keyboard shortcut in the shortcut details."
else
echo "Failed to sign the macOS shortcut; skipping shortcut setup."
fi
}
main() {
local target version download_url
# Step 1: Detect platform
echo "Detecting platform..."
target=$(detect_platform)
echo "Platform: ${target}"
# Step 2: Get latest version from GitHub
echo "Fetching latest version..."
version=$(get_latest_version)
if [[ -z "${version}" ]]; then
echo "Failed to fetch latest version" >&2
exit 1
fi
echo "Version: ${version}"
# Step 3: Download and extract the binary
download_url="https://github.com/${REPO}/releases/download/${version}/wiggly-${target}.tar.gz"
echo "Downloading wiggly..."
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "${TEMP_DIR}"' EXIT
curl -sSL "${download_url}" | tar -xz -C "${TEMP_DIR}"
# Step 4: Install to ~/.local/bin
echo "Installing to ${INSTALL_DIR}..."
mkdir -p "${INSTALL_DIR}"
mv "${TEMP_DIR}/wiggly" "${INSTALL_DIR}/wiggly"
chmod +x "${INSTALL_DIR}/wiggly"
# Step 5: Configure PATH if needed
if [[ ":${PATH}:" != *":${INSTALL_DIR}:"* ]]; then
configure_path
fi
register_macos_shortcut
echo ""
echo "wiggly ${version} installed successfully!"
}
main