38
39
print_usage() {
40
printf '%s\n' \
41
- 'Usage: install.sh [--agent] [--no-plugins] [version-tag]' \
41
+ 'Usage: install.sh [--agent] [--no-plugins] [--shell zsh|bash|fish] [version-tag]' \
42
'' \
43
'Options:' \
44
- ' --agent Sign up or log in as a Composio agent after installation.' \
45
- ' --no-plugins Skip agent plugin installation (the default).' \
46
- ' -h, --help Show this help.' \
44
+ ' --agent Sign up or log in as a Composio agent after installation.' \
45
+ ' --no-plugins Skip agent plugin installation (the default).' \
46
+ ' --shell <shell> Configure zsh, bash, or fish so the composio command is on PATH.' \
47
+ ' -h, --help Show this help.' \
48
'' \
49
'Version tags may be stable or beta, for example 0.3.1 or @composio/cli@0.3.1-beta.329.'
50
}
275
esac
276
}
277
278
+is_unsafe_path() {
279
+ case $1 in *':'* | *';'* | *'`'* | *'$'* | *'|'* | *'&'* | *'"'* | *"'"* | *'('* | *')'* | *\\*) return 0 ;; esac
280
+ unsafe_path_cr=$(printf '\r')
281
+ case $1 in *"$unsafe_path_cr"* | *'
282
+'*) return 0 ;; esac
283
+ return 1
284
+}
285
+
286
+render_bin_dir() {
287
+ render_bin_dir_value=$1
288
+ case $render_bin_dir_value in "$HOME"/*) render_bin_dir_value=\$HOME/${render_bin_dir_value#"$HOME"/} ;; esac
289
+ printf '%s\n' "$render_bin_dir_value"
290
+}
291
+
292
+append_path_block() {
293
+ append_path_file=$1
294
+ append_path_shell=$2
295
+ append_path_bin=$3
296
+ mkdir -p "$(dirname "$append_path_file")"
297
+ touch "$append_path_file"
298
+ grep -Fqx '# Composio CLI' "$append_path_file" 2>/dev/null && return 0
299
+ case $append_path_shell in
300
+ fish) append_path_line="set --export PATH \"$append_path_bin\" \$PATH" ;;
301
+ *) append_path_line="export PATH=\"$append_path_bin:\$PATH\"" ;;
302
+ esac
303
+ printf '\n# Composio CLI\n%s\n' "$append_path_line" >>"$append_path_file"
304
+}
305
+
306
+inline_shell_setup() {
307
+ inline_setup_shell=$1
308
+ inline_setup_bin_dir=$2
309
+ is_unsafe_path "$inline_setup_bin_dir" && error "COMPOSIO_BIN_DIR contains unsafe characters"
310
+ inline_setup_rendered=$(render_bin_dir "$inline_setup_bin_dir")
311
+ case $inline_setup_shell in
312
+ zsh) append_path_block "$HOME/.zshrc" zsh "$inline_setup_rendered" ;;
313
+ fish) append_path_block "$HOME/.config/fish/config.fish" fish "$inline_setup_rendered" ;;
314
+ bash)
315
+ append_path_block "$HOME/.bashrc" bash "$inline_setup_rendered"
316
+ if [ -f "$HOME/.bash_profile" ]; then
317
+ append_path_block "$HOME/.bash_profile" bash "$inline_setup_rendered"
318
+ elif [ -f "$HOME/.bash_login" ]; then
319
+ append_path_block "$HOME/.bash_login" bash "$inline_setup_rendered"
320
+ fi
321
+ ;;
322
+ esac
323
+}
324
+
325
+setup_requested_shell() {
326
+ if "$exe" install --help 2>&1 | grep -q -- '--shell'; then
327
+ debug "delegating shell setup to $exe install --shell $requested_shell"
328
+ if COMPOSIO_CLI_INVOCATION_ORIGIN=installer COMPOSIO_BIN_DIR="$COMPOSIO_BIN_DIR" "$exe" install --shell "$requested_shell"; then
329
+ shell_configured=cli
330
+ else
331
+ debug "falling back to inline $requested_shell shell setup"
332
+ inline_shell_setup "$requested_shell" "$COMPOSIO_BIN_DIR"
333
+ shell_configured=fallback
334
+ fi
335
+ else
336
+ debug "falling back to inline $requested_shell shell setup"
337
+ inline_shell_setup "$requested_shell" "$COMPOSIO_BIN_DIR"
338
+ shell_configured=fallback
339
+ fi
340
+
341
+ info "Configured $requested_shell shell setup ($shell_configured)."
342
+ case $requested_shell in
343
+ zsh) info "Restart your shell or run \`source ~/.zshrc\`." ;;
344
+ bash) info "Restart your shell or run \`source ~/.bashrc\`." ;;
345
+ fish) info "Restart your shell or run \`source ~/.config/fish/config.fish\`." ;;
346
+ esac
347
+}
348
+
349
print_post_install_help() {
350
[ "${COMPOSIO_INSTALL_HELP:-1}" != 0 ] || return 0
351
is_true "${COMPOSIO_QUIET:-}" && return 0
376
fi
377
378
printf '\n'
307
- if [ -n "$shell_route" ]; then
379
+ if [ -n "$requested_shell" ]; then
380
+ : # Shell setup already ran; skip the setup suggestion.
381
+ elif [ -n "$shell_route" ]; then
382
if [ "$guidance_required" = 1 ]; then
383
printf 'Required next step for %s:\n\n' "$shell_name"
384
else
385
printf 'Optional shell setup for future PATH changes:\n\n'
386
fi
313
- printf ' curl -fsSL https://composio.dev/install/%s | sh\n' "$shell_route"
387
+ printf ' curl -fsSL https://composio.dev/install | sh -s -- --shell %s\n' "$shell_route"
388
printf '\nThis configures %s.\n' "$shell_config"
389
elif path_contains_bin_dir; then
390
printf 'The composio command is available on PATH.\n'
411
install_agent=0
412
install_plugins=${COMPOSIO_INSTALL_PLUGINS:-0}
413
version_arg=
414
+ requested_shell=
415
416
case $install_plugins in
417
0 | 1) ;;
422
case $1 in
423
--agent) install_agent=1 ;;
424
--no-plugins) install_plugins=0 ;;
425
+ --shell)
426
+ [ "$#" -ge 2 ] || error '--shell requires a value: zsh, bash, or fish'
427
+ case $2 in
428
+ zsh | bash | fish) requested_shell=$2 ;;
429
+ *) error "Invalid --shell value \"$2\". Expected zsh, bash, or fish." ;;
430
+ esac
431
+ shift
432
+ ;;
433
-h | --help)
434
print_usage
435
return 0
541
error 'Failed to sign up or log in as a Composio agent.'
542
fi
543
544
+ if [ -n "$requested_shell" ]; then
545
+ setup_requested_shell
546
+ fi
547
+
548
print_post_install_help
549
}
550