From 2340e7e6e5eadf1fe920db4c276716d661a704b4 Mon Sep 17 00:00:00 2001 From: Hyro Date: Sat, 3 Sep 2022 14:01:26 +0200 Subject: [PATCH] chore(install-script): automatically add bun to path - bash shell (#1168) * chore(install-script): automatically add bun to path - bash shell * add tildify * chore: make requested changes * fix: add equals true Co-authored-by: Wallunen <44848747+Wallunen@users.noreply.github.com> * fix: $XDG_CONFIG_HOME can be undefined Co-authored-by: Wallunen <44848747+Wallunen@users.noreply.github.com> Co-authored-by: Wallunen <44848747+Wallunen@users.noreply.github.com> --- src/cli/install.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/cli/install.sh b/src/cli/install.sh index dc9f6aa4c2..b9cc03cd3f 100644 --- a/src/cli/install.sh +++ b/src/cli/install.sh @@ -226,6 +226,55 @@ zsh) done fi ;; +bash) + commands=( + "export $install_env=$quoted_install_dir" + "export PATH=$bin_env:\$PATH" + ) + + bash_configs=( + "$HOME/.bashrc" + "$HOME/.bash_profile" + ) + + if [[ ${XDG_CONFIG_HOME:-} ]]; then + bash_configs+=( + "$XDG_CONFIG_HOME/.bash_profile" + "$XDG_CONFIG_HOME/.bashrc" + "$XDG_CONFIG_HOME/bash_profile" + "$XDG_CONFIG_HOME/bashrc" + ) + fi + + set_manually=true + for bash_config in "${bash_configs[@]}"; do + tilde_bash_config=$(tildify "$bash_config") + + if [[ -w $bash_config ]]; then + { + echo -e '\n# bun' + + for command in "${commands[@]}"; do + echo "$command" + done + } >>"$bash_config" + + info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_bash_config\"" + + refresh_command="source $bash_config" + set_manually=false + break + fi + done + + if [[ $set_manually = true ]]; then + echo "Manually add the directory to $tilde_bash_config (or similar):" + + for command in "${commands[@]}"; do + info_bold " $command" + done + fi + ;; *) echo 'Manually add the directory to ~/.bashrc (or similar):' info_bold " export $install_env=$quoted_install_dir"