69
fi
70
}
71
72
+# Escape a value for embedding inside a double-quoted shell rc line, so an
73
+# install directory containing `$(...)`, a backtick, or a quote is written as
74
+# literal text instead of becoming live code the next time the rc is sourced.
75
+# Backslashes must be escaped first. The second argument selects whether
76
+# backticks are escaped: bash and zsh perform backtick substitution inside
77
+# double quotes, fish does not — and fish does not recognize \` there either,
78
+# so escaping it for fish would corrupt the path.
79
+escape_for_double_quotes() {
80
+ local value=$1 escape_backticks=${2:-true}
81
+ value=${value//\\/\\\\}
82
+ if [[ $escape_backticks = true ]]; then
83
+ value=${value//\`/\\\`}
84
+ fi
85
+ value=${value//\$/\\\$}
86
+ value=${value//\"/\\\"}
87
+ printf '%s' "$value"
88
+}
89
+
90
install_agent=false
91
install_plugins=true
92
version_arg=""
340
info "Setting up shell integration..."
341
342
refresh_command=''
325
- quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
343
327
- if [[ $quoted_install_dir = \"$HOME/* ]]; then
328
- quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
344
+ # Every rc line below embeds one of these inside double quotes. `$HOME` is
345
+ # re-applied after escaping so the intended variable reference survives as
346
+ # a literal `$HOME` while any user-supplied `$` stays escaped.
347
+ escaped_install_dir=$(escape_for_double_quotes "$COMPOSIO_INSTALL_DIR")
348
+ escaped_install_dir_fish=$(escape_for_double_quotes "$COMPOSIO_INSTALL_DIR" false)
349
+ home_relative_install_dir=$escaped_install_dir
350
+
351
+ if [[ $COMPOSIO_INSTALL_DIR = "$HOME"/* ]]; then
352
+ home_relative_install_dir='$HOME/'$(escape_for_double_quotes "${COMPOSIO_INSTALL_DIR#"$HOME"/}")
353
fi
354
355
shell_name=$(basename "${SHELL:-}")
358
case $shell_name in
359
fish)
360
commands=(
337
- "set --export COMPOSIO_INSTALL_DIR \"$COMPOSIO_INSTALL_DIR\""
361
+ "set --export COMPOSIO_INSTALL_DIR \"$escaped_install_dir_fish\""
362
"set --export PATH \$COMPOSIO_INSTALL_DIR \$PATH"
363
)
364
fish_config=$HOME/.config/fish/config.fish
378
;;
379
zsh)
380
commands=(
357
- "export COMPOSIO_INSTALL_DIR=\"$COMPOSIO_INSTALL_DIR\""
381
+ "export COMPOSIO_INSTALL_DIR=\"$escaped_install_dir\""
382
"export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
383
)
384
zsh_config=$HOME/.zshrc
398
;;
399
bash)
400
commands=(
377
- "export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
401
+ "export COMPOSIO_INSTALL_DIR=\"$home_relative_install_dir\""
402
"export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
403
)
404
bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
426
;;
427
*)
428
echo 'Manually add the directory to ~/.bashrc (or similar):'
405
- info_bold " export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
429
+ info_bold " export COMPOSIO_INSTALL_DIR=\"$home_relative_install_dir\""
430
info_bold " export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
431
;;
432
esac